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 ...
随机推荐
- IDEA开发环境设置
IDEA开发环境设置 1.关闭自动更新 IntelliJ IDEA默认会自动进行版本的更新,在网络异常时经常会导致各种各样的问题,因此强烈建议关闭自动更新. File->Settings 2.隐 ...
- dom元素的自上而下自动滚动
dom元素的自上而下自动滚动 <!doctype html> <html lang="en"> <head> <meta charset= ...
- 时间、金钱在java、数据库中的变量类型之总结
在编写程序时,总是有些变量的类型搞不很明白,现将目前涉及到的变量总结一下: 1.“时间”类型 (1).在数据库中的变量类型是:DateTime 比如: operateTime DATETIME,//数 ...
- 洛谷P2460 [SDOI2007]科比的比赛(题解)(贪心+搜索)
科比的比赛(题解)(贪心+搜索) 标签:算法--贪心 阅读体验:https://zybuluo.com/Junlier/note/1301158 贪心+搜索 洛谷题目:P2460 [SDOI2007] ...
- jQuery难学是因为什么?
我们看别人写的js代码,发现很多不明白,其实只是你对语法不清楚.对函数方法了解的不全面. /****************************************************** ...
- SpringBoot 集成MyBatis 中的@MapperScan注解
SpringBoot 集成MyBatis 中的@MapperScan注解 2018年08月17日 11:41:02 文火慢炖 阅读数:398更多 个人分类: 环境搭建 在SpringBoot中集成My ...
- Log4Net 之将日志记录到数据库的配置 (一)
原文:Log4Net 之将日志记录到数据库的配置 (一) 前段时间我一直想做一个通用一点的日志记录系统,可以便于不同的业务组调用进行日志记录及分析.本来打算着自己下手写一个,后面发现各业务组可能会需要 ...
- Sql Server中的标识列(自增长字段)
一.标识列的定义以及特点 SQL Server中的标识列又称标识符列,习惯上又叫自增列.该种列具有以下三种特点: 1.列的数据类型为不带小数的数值类型2.在进行插入(Insert)操作时,该列的值是由 ...
- 三、Windows下用FFmpeg+nginx+rtmp搭建直播环境 实现推流、拉流
一.环境 1.开发环境:windows 2.开发工具:FFmpeg.nginx.nginx-rmtp-module (链接:https://pan.baidu.com/s/119d2GeMzddas_ ...
- codeforces Summer Earnings(bieset)
Summer Earnings time limit per test 9 seconds memory limit per test 256 megabytes input standard inp ...