1208C Magic Grid
题目大意
给你一个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的更多相关文章
- AMR11A - Magic Grid
Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did ...
- Spring-2-A Magic Grid(SPOJ AMR11A)解题报告及测试数据
Magic Grid Time Limit:336MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Tha ...
- C. Magic Grid 构造矩阵
C. Magic Grid time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Magic Grid ComboBox JQuery 版
在MagicCombo组件中嵌入Grid,以支持分页查找和跨页选取 1. 2. [代码][JavaScript]单选示例代码 <script type="text/jav ...
- CF-1208 C.Magic Grid
题目 大意:构造一个n行n列的矩阵,使得每一行,每一列的异或和都相等,n是4的倍数. 先看4*4的矩阵,我们很容易构造出符合要求的矩阵,比如 0 1 2 3 4 5 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 ...
- 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 ...
- B. Chris and Magic Square
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 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 ...
随机推荐
- 20190925 On Java8 第二十二章 枚举
第二十二章 枚举 基本 enum 特性 创建 enum 时,编译器会为你生成一个相关的类,这个类继承自 Java.lang.Enum. valueOf() 是在 Enum 中定义的 static 方法 ...
- python 操作ssh登录
import paramiko #创建SSH对象 ssh = paramiko.SSHClient() #把要连接的机器添加到known_hosts文件中 ssh.set_missing_host_k ...
- 实列+JVM讲解类的实列化顺序
刨根问底---类的实列化顺序 开篇三问 1什么是类的加载,类的加载和类的实列有什么关系,什么时候类加载 2类加载会调用构造函数吗,什么时候调用构造函数 3什么是实列化对象,实列化的对象有什么东西. 我 ...
- Web API入门二(实例)
学习编程的最好方法就是实例,本人用的是VS2015 1.创建ASP.NET Web空项目 点击确定后即创建了空"WebApi"项目 2.下面,我们需要使用NuGet包管理器添加最新 ...
- JDK11 | 第五篇 : 启动单个Java源代码文件的程序
文章首发于公众号<程序员果果> 地址 : https://mp.weixin.qq.com/s/h1L4FmzVSix434gVt8Fc7w 一.简介 JEP330-启动单文件代码程序(L ...
- java变量的类型
变量的类型 一 按数据类型分: 1.基本数据类型 : 整型 : byte (1字节 - (-128 ~ 127)) short (2字节) int (4字节) long (8字节) 浮点型 : ...
- Vert.x学习第一天
昨天看了下异步,然后就开始了Vert.x相关知识的学习. Vert.x是当下非常流行的一套全异步框架,其优势在于轻量级.高效.非常适合作为移动端后台或是企业应用. 当然对于第一天接触这个框架的人(没错 ...
- vi编辑器没有颜色的解决办法
Centos里的VI只默认安装了vim-minimal-7.x.所以无论是输入vi或者vim查看文件,syntax功能都无法正常启用.因此需要用yum安装另外两个组件:vim-common-7.x和v ...
- k3 cloud单据体首行过滤功能
#实现单据体首行过滤 clr.AddReference('System') clr.AddReference('Kingdee.BOS.Core') from Kingdee.BOS.Core.Dy ...
- vue.js(11)--案例--关键字搜索列表
关键字搜索品牌案例 (1)页面布局 <div class="app"> <div class="panel panel-primary"> ...