Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造

【Problem Description】
给你一个\(n\),构造一个\(n\times n\)的矩阵,使其满足任意一行,或一列的异或值相同。保证\(n\)能被\(4\)整除。
【Solution】
可以发现,从\(0\)开始,每\(4\)个连续数的异或值为\(0\),所以可以很容易使得每一行的异或值等于\(0\)。
列向可以发现,从\(0\)开始,公差为\(4\)的,每\(4\)个数的异或值也为\(0\)。即\(0\oplus4\oplus8\oplus12=0\)。所以满足条件的矩阵形如:
0&1&2&3&32&33&34&35&\\
4&5&6&7&36&37&38&39&\\
8&9&10&11&40&41&42&43&\\
12&13&14&15&44&45&46&47&\\
16&17&18&19&48&49&50&51&\\
20&21&22&23&52&53&54&55&\\
24&25&26&27&56&57&58&59&\\
28&29&30&31&60&61&62&63&\\
\end{matrix}\right]
\]
【Code】
/*
* @Author: Simon
* @Date: 2019-08-26 18:38:05
* @Last Modified by: Simon
* @Last Modified time: 2019-08-26 19:02:53
*/
#include<bits/stdc++.h>
using namespace std;
typedef int Int;
#define int long long
#define INF 0x3f3f3f3f
#define maxn 2005
int a[maxn][maxn];
Int main(){
#ifndef ONLINE_JUDGE
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
for(int i=0;i<n;i++) a[0][i]=i/4*n*4+i%4;
for(int i=1;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]=a[i-1][j]+4;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<' ';
}
cout<<endl;
}
#ifndef ONLINE_JUDGE
system("pause");
#endif
return 0;
}
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造的更多相关文章
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Pro ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构 [Problem ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) F. Bits And Pieces sosdp
F. Bits And Pieces 题面 You are given an array
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) G. Polygons 数论
G. Polygons Description You are given two integers
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) (1208F,1208G,1208H)
1208 F 大意: 给定序列$a$, 求$\text{$a_i$|$a_j$&$a_k$}(i<j<k)$的最大值 枚举$i$, 从高位到低位贪心, 那么问题就转化为给定$x$ ...
- RMQ+差分处理(Let Them Slide)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1208/problem/E 现有n行w列的墙,每行有一排连续方块,一排方块可以左右连续滑动,且每个方块都有一个价值,第i 列的价值定义为 ...
- 线段树维护最后一个0的位置(Restore Permutation)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1208/problem/D 给你长度为n的序列,s[i]的值为p[1]到p[i-1]中比p[i]小的数的和,让你求出p序列. 思路: 首 ...
- Codeforces Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
传送门 A. XORinacci 手玩三四项发现序列就是 $a,b,a\ xor\ b,a,b,...$,直接输出即可 #include<iostream> #include<cst ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)E(多重集维护)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long ans[1000007]; ...
随机推荐
- html的rowspan和colspan
https://www.jb51.net/article/165695.htm rowspan工具 https://blog.csdn.net/oxiaobaio/article/details/80 ...
- K8S使用入门-添加一个node
上一篇博客我们已经将K8S部署起来了,现在我们就来介绍一下如何简单使用K8S (1)添加节点 注意事项:不能和k8s master节点的主机名一样.否则会导致k8s无法正常识别出该节点 添加节点是比较 ...
- UE4 移动物体的几种方法
转自:https://dawnarc.com/2016/06/ue4%E7%A7%BB%E5%8A%A8%E7%89%A9%E4%BD%93%E7%9A%84%E5%87%A0%E7%A7%8D%E6 ...
- 【插件】【idea】的Mybatis Plugin插件方便mapper接口方法和mapper XML文件之间来回切换
效果 安装 这是2019.2版本的,旧版的有点不一样
- sql调优方法实用性总结(一)
1.选择最有效率的表名顺序(只在基于规则的优化器): Oracle的解析器按照从右向左的顺序处理FROM子句中的表名,FROM子句中写在最后的表将被最先处理(基础表先处理,driving table) ...
- 分布式事务的 N 种实现
转自:http://myfjdthink.com/2019/04/26/%E5%88%86%E5%B8%83%E5%BC%8F%E4%BA%8B%E5%8A%A1%E7%9A%84-n-%E7%A7% ...
- Win10最详细的优化设置 完美解决磁盘100%占用
1.用360优化win10后开不了机的问题原因是禁用了三个服务:在360应用软件服务里dmwappushsvc.diagnsticsTrackingservice.coreMessaging这三个要开 ...
- redis连接池(JedisPool)资源归还及timeout详解
转载. https://blog.csdn.net/yaomingyang/article/details/79043019 一.连接池资源类详解都在注释上 package redis.v1.clie ...
- string字符串成员函数
string字符串成员函数 string str1="aaa"; char c='c'; str1.assign("ABCAAAAAAABBBBB");//替换 ...
- setPos 详解
etWindowPos 详解 函数名: SetWindowPos 头文件: winuser.h 函数原型: BOOL SetWindowPos ( HWND hWnd, //窗口句柄 HWND h ...