题解 CF1208C 【Magic Grid】

foreverlasting

2019-08-30 17:04:45

Solution

[推销博客](https://foreverlasting1202.github.io/2019/08/27/CF1208%E9%A2%98%E8%A7%A3/) ### C Magic Grid 题意:给一个$n$,需要构造一个$n*n$的矩阵,包含$0,...,n^2-1$,且每行每列的异或和相等。$4\leq n\leq 4000,4|n$。 做法:每$4*4$的为一组,显然可以构造出都为$0$的情况,复杂度$O(n^2)$。 code: ```cpp //2019.8.24 by ljz //email [email protected] //if you find any bug in my code //please tell me #include<bits/stdc++.h> using namespace std; #define res register int #define LL long long #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f #define unl __int128 #define eps 5.6e-8 #define RG register #define db double #define pc(x) __builtin_popcount(x) typedef pair<int,int> Pair; #define mp make_pair #define fi first #define se second #define pi acos(-1.0) #define pb push_back #define ull unsigned LL #define gc getchar //inline char gc() { // static char buf[100000],*p1,*p2; // return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; //} //inline int read() { // res s=0,ch=gc(); // while(ch<'0'||ch>'9')ch=gc(); // while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); // return s; //} inline int read() { res s=0,ch=gc(),w=1; while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();} while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); return s*w; } inline LL Read() { RG LL s=0; res ch=gc(); while(ch<'0'||ch>'9')ch=gc(); while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); return s; } //inline LL Read() { // RG LL s=0; // res ch=gc(),w=1; // while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();} // while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); // return s*w; //} //inline void write(RG unl x){ // if(x>10)write(x/10); // putchar(int(x%10)+'0'); //} inline void swap(res &x,res &y) { x^=y^=x^=y; } //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //clock_t start=clock(); //inline void ck(){ // if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0); //} //const int N=1e6+10; namespace MAIN{ const int N=2005; int M[N][N],n,c; void solve(res l,res r,res ql,res qr){for(res i=l;i<=r;i++)for(res j=ql;j<=qr;j++)M[i][j]=c++;} inline void MAIN(){ scanf("%d",&n); for(res i=1;i<=n>>2;i++)for(res j=1;j<=n>>2;j++)solve((i-1)*4+1,i*4,(j-1)*4+1,j*4); for(res i=1;i<=n;i++){ for(res j=1;j<=n;j++) printf("%d ",M[i][j]); puts(""); } } } int main(){ // srand(19260817); // freopen("signin.in","r",stdin); // freopen("signin.out","w",stdout); MAIN::MAIN(); return 0; } ```