The 1st Universal Cup Stage 5: Osijek, February 25-26, 2023 题解

Posted nike0good

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The 1st Universal Cup Stage 5: Osijek, February 25-26, 2023 题解相关的知识,希望对你有一定的参考价值。

G

Problem G. Gridlandia
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
给一个 n ∗ n n*n nn的矩阵,每个格子可以选取上下左右一条边(可以不选),所有选取的边不能共点。现在要求构造一个方案,选尽量多的边。

The continent of Gridlandia is a squares of side length n, divided into n2 square contries of side length. Each country has the resources to choose at most one of its four sides and build a ‘wall’ covering that entire side. However, since all the countries are at war, no two countries are willing to have their walls touch, even at the wall’s endpoints.
Find the maximum number of walls that can be built in Gridlandia, and construct a configuration where the maximum number of walls are built.
Input
The only line of input contains a single integer n (1 ≤ n ≤ 103) – the number of squares on each side of the grid.
Output
The output should consist of n lines.
Each line should contain n characters, each being blank (represented by ‘.’) or one of ‘ULDR’.
A dot represents a country with no walls, whereas each of the characters ‘ULDR’ represents a country that builds a wall on its ‘Up’, ‘Down’, ‘Left’, and ‘Right’ sides respectively.

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n)  \\
						For(j,m-1) cout<<a[i][j]<<' ';\\
						cout<<a[i][m]<<endl; \\
						 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b)return (a*b)%F;
ll add(ll a,ll b)return (a+b)%F;
ll sub(ll a,ll b)return ((a-b)%F+F)%F;
void upd(ll &a,ll b)a=(a%F+b%F)%F;
inline int read()

	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) if (ch=='-') f=-1; ch=getchar();
	while(isdigit(ch))  x=x*10+ch-'0'; ch=getchar();
	return x*f;
 
#define MAXN (1010)
char f[MAXN][MAXN];
int n;
bool inside(int i) 
	return 1<=i&&i<=n;

bool inside(int i,int j) 
	return inside(i)&inside(j);


bool ck(int i,int j ,int p) 
	if(!inside(i,j) || f[i][j]=='.') return 1;
	if(p==0) 
		return (f[i][j]=='D')||(f[i][j]=='R');
	
	if(p==1) 
		return (f[i][j]=='D')||(f[i][j]=='L');
	
	if(p==2) 
		return (f[i][j]=='U')||(f[i][j]=='R');
	
	if(p==3) 
		return (f[i][j]=='U')||(f[i][j]=='L');
	

bool ck(int i,int j,int p,int p2) 
	return ck(i,j,p)&&ck(i,j,p2);

int ct=0;
void dfs(int i,int j,int s=0) 
	int id=n*(i-1)+j;
	if(n*n-id+s<ct) return;
	if(i==n+1 && j==1) 
//		if(s==9) 
			For(i,n) 
				For(j,n) putchar(f[i][j]);cout<<endl;
			
//		
//		cout<<s<<endl;
		exit(0);
		gmax(ct,s)
		return ;
	
	int ni=i,nj=j+1;
	if(j==n) ni=i+1,nj=1;
	
	f[i][j]='U';
	if(ck(i,j-1,1)&&ck(i-1,j,2,3)&&ck(i-1,j-1,3)&&ck(i-1,j+1,2)) 
		dfs(ni,nj,s+1);
		
	f[i][j]='L';
	if(ck(i-1,j,2)&&ck(i-1,j-1,3)&&ck(i,j-1,1,3) ) 
		dfs(ni,nj,s+1);
		
	f[i][j]='D';
	if(ck(i,j-1,3) ) 
		dfs(ni,nj,s+1);
		
	f[i][j]='R';
	if(ck(i-1,j,3) && ck(i-1,j+1,2)) 
		dfs(ni,nj,s+1);
		
	f[i][j]='.';
	dfs(ni,nj,s);
	
		

int main()

//	freopen("D.in","r",stdin);
//	freopen(".out","w",stdout);
	
	cin>>n;
	dfs(1,1);
//	cout<<ct;
	return 0;


I Julienne the Deck

给一个长度为n的排列 1 , ⋯   , n 1,\\cdots,n 1,,n,每次操作可以选择 i ( 1 ≤ i < n ) i(1\\le i \\lt n) i(1i<n) $并同时翻转前i个数和后n-i个数,问最后可形成的排列数。

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D以上是关于The 1st Universal Cup Stage 5: Osijek, February 25-26, 2023 题解的主要内容,如果未能解决你的问题,请参考以下文章

HDU 5999: The Third Cup is Free

Reference Collapsing Rules, Universal Reference and the implementation of std::forward() and std::mo

life|October the 1st| five twenty|three–fifths|1970s|30s

World Cup(The 2016 ACM-ICPC Asia China-Final Contest dfs搜索)

The 1st Challenge on Remote Physiological Signal Sensing (RePSS) CVPR2020人脸心率估计竞赛

codeforces Looksery Cup 2015 H Degenerate Matrix