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\)。所以满足条件的矩阵形如:

\[\left[\begin{matrix}
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-构造的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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

  4. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) G. Polygons 数论

    G. Polygons Description You are given two integers

  5. 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$ ...

  6. 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 列的价值定义为 ...

  7. 线段树维护最后一个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序列. 思路: 首 ...

  8. 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 ...

  9. 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]; ...

随机推荐

  1. CKA认证简介

  2. win32 event事件

    原文地址:https://blog.csdn.net/u011394598/article/details/82981399 SetEvent/ResetEvent分别将EVENT置为这两种状态分别是 ...

  3. ORA-01126: 数据库必须已装载到此实例并且不在任何实例中打开

    原因:修改归档模式的操作只能在 mount 状态下进行,不能处于 open 状态. SQL> alter database archivelog;alter database archivelo ...

  4. LeetCode 1046. 最后一块石头的重量(1046. Last Stone Weight) 50

    1046. 最后一块石头的重量 1046. Last Stone Weight 题目描述 每日一算法2019/6/22Day 50LeetCode1046. Last Stone Weight Jav ...

  5. SQL IN 子查询返回多对值

    我们常用的IN 操作是这样的: select * from tab twhere t.col1 in ('value1''value2');12但是如果是多个列的取值来自同一个子查询呢? 我们是不是要 ...

  6. Python中使用@的理解

    Python函数中使用@ 稍提一下的基础 fun 和fun()的区别 以一段代码为例: def fun(): print('fun') return None a = fun() #fun函数并将返回 ...

  7. 唯一ID生成器--雪花算法

    在微服务架构,分布式系统中的操作会有一些全局性ID的需求,所以我们不能用数据库本身的自增功能来产生主键值,只能由程序来生成唯一的主键值.我们采用的是twitter的snokeflake(雪花)算法. ...

  8. RabbitMQ之消息模式(下)

    目的: RabbitMQ之消息模式(上):https://www.cnblogs.com/huangting/p/11994539.html 消费端限流 消息的ACK与重回队列 TTL消息 死信队列 ...

  9. centos7搭建gitlab仓库

    在有一些企业里会搭建属于自己的代码仓库,只能内网访问,所以说今天在centos7中搭建了一个gitlab仓库,大家也可以搭建一个玩一玩.呵呵 1.首先安装依赖软件包和开启ssh服务: sudo yum ...

  10. python ---升级所有安装过的package

    # -*- coding:utf8 -*- import pip from subprocess import call from pip._internal.utils.misc import ge ...