题目大意

给你一个n

让你用0~n^2-1的数填满一个n*n的正方形

满足每个数值出现一次且每行每列的异或值相等

输出任意一种方案

分析

我们发现对于4*4的正方形

0  1  2  3

4  5  6  7

8  9 10 11

12 13 14 15

是满足条件的

那么如果对正方形中的每一个数都加上一个相同的数

那么这个正方形一定还是满足的

由于这种构造方式的异或值均是0

所以任意多个满足的正方形拼起来一定也是满足的

于是我们将正方形分为若干4*4的正方形

使得每一个正方形是一组连续的数

那么不难发现一定满足条件

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int g[][],cnt;
int main(){
int n,m,i,j,k,t;
scanf("%d",&n);
for(i=;i<=n;i+=)
for(j=;j<=n;j+=)
for(k=;k<;k++)
for(t=;t<;t++)
g[i+k][j+t]=cnt++;
for(i=;i<=n;i++){
for(j=;j<=n;j++)printf("%d ",g[i][j]);
puts("");
}
return ;
}

1208C Magic Grid的更多相关文章

  1. AMR11A - Magic Grid

    Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did ...

  2. Spring-2-A Magic Grid(SPOJ AMR11A)解题报告及测试数据

    Magic Grid Time Limit:336MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Tha ...

  3. C. Magic Grid 构造矩阵

    C. Magic Grid time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Magic Grid ComboBox JQuery 版

    在MagicCombo组件中嵌入Grid,以支持分页查找和跨页选取 ​ 1. ​2. [代码][JavaScript]单选示例代码     <script type="text/jav ...

  5. CF-1208 C.Magic Grid

    题目 大意:构造一个n行n列的矩阵,使得每一行,每一列的异或和都相等,n是4的倍数. 先看4*4的矩阵,我们很容易构造出符合要求的矩阵,比如 0    1    2    3 4    5    6  ...

  6. Codeforces Round #369 (Div. 2) B. Chris and Magic Square 水题

    B. Chris and Magic Square 题目连接: http://www.codeforces.com/contest/711/problem/B Description ZS the C ...

  7. Chris and Magic Square CodeForces - 711B

    ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid o ...

  8. B. Chris and Magic Square

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. Codeforces Round #369 (Div. 2) B. Chris and Magic Square (暴力)

    Chris and Magic Square 题目链接: http://codeforces.com/contest/711/problem/B Description ZS the Coder an ...

随机推荐

  1. 安全运维 - Linux系统攻击应急响应

    Linux 应急相应 - 总纲 应急准备: 制定应急策略 组建应急团队 其他应急资源 安全事件处理: 痕迹数据获取 分析.锁定攻击源删除可疑账号关闭异常进程.端口禁用相应异常开机启动项删除异常定时任务 ...

  2. linux如何处理多连接请求?

    1.TCP迭代服务器程序 这种方式就是服务器同一时间只处理一个客户端的请求,这个请求处理完以后才转向下一个客户请求.当然这样的服务器程序比较少见,这就像一个公司只能一次处理一个客户,后面的客户只能等待 ...

  3. 20190909 SpringBoot集成Swagger

    SpringBoot集成Swagger 1. 引入依赖 // SpringBoot compile('org.springframework.boot:spring-boot-starter-web' ...

  4. ceph部署-常用命令

    常用命令:1.ceph healthceph -s 2.ceph osd treeceph osd lspoolsceph osd pool [poolname] rbd pg_numceph osd ...

  5. Django forms组件的校验

    引入: from django import forms 使用方法:定义规则,例: class UserForm(forms.Form): name=forms.CharField(max_lengt ...

  6. CSS-子盒子撑开父盒子,让父盒子的高随内容自适应

    方法一: height:auto!important; height:200px; min-height:200px; ie6并不支持min-height.ie7,opera,火狐没有问题. 方法二: ...

  7. go中string类型转换为基本数据类型的方法

    代码 // string类型转基本数据类型 package main import ( "fmt" "strconv" ) func main() { str1 ...

  8. tf.clip_by_global_norm

    首先明白这个事干嘛的,在我们做求导的时候,会遇到一种情况,求导函数突然变得特别陡峭,是不是意味着下一步的进行会远远高于正常值,这个函数的意义在于,在突然变得陡峭的求导函数中,加上一些判定,如果过于陡峭 ...

  9. RocketMQ集群部署安装

    RcoketMQ:[ 1.低延时:在高压下,1毫秒内超过99.6%的反应延迟. 2.面向金融:具有跟踪和审计功能的高可用性. 3.行业可持续发展:保证了万亿级的消息容量. 4.厂商中立:一个新的开放的 ...

  10. [POI2007]POW-The Flood(并查集)

    [POI2007]POW-The Flood Description AKD 市处在一个四面环山的谷地里.最近一场大暴雨引发了洪水,AKD 市全被水淹没了.Blue Mary,AKD 市的市长,召集了 ...