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 ...
随机推荐
- 浅谈Vue中的$set的使用
在我们使用vue进行开发的过程中,可能会遇到一种情况:当生成vue实例后,当再次给数据赋值时,有时候并不会自动更新到视图上去: 当我们去看vue文档的时候,会发现有这么一句话:如果在实例创建之后添加新 ...
- 建立 Active Directory域 ----学习笔记
第五章 建立 Active Directory域 1.工作组和域的理解 a.工作组是一种平等身份环境,各个计算机之间各个为一个独立体,不方便管理和资源共享. b.域环境一般情况下满足两类需求, ...
- HTTP response status
The status code is a 3-digit number: 1xx (Informational): Request received, server is continuing the ...
- jdk与eclipse安装注意事项
1.安装这两个软件,一定要注意使得两个软件的版本是一致的: 1.1编写小程序测试jdk的版本号: public class Text{ public static void main(String[] ...
- Java中的常用类:包装类、String、StringBuffer、StringBuilder、Math、System、Arrays、BigInteger、BigDecimal、Data、Calendar
一.包装类 √ 二.String类 ★ 三.StringBuffer和StringBuilder类 ★ 四.Math类 五.System类 六.Arrays类 七.BigInteger类和BigDec ...
- (六:NIO系列) 相关设计模式
出处: 反应器模式 vs 观察者模式 反应器模式 vs 生产者消费者模式 反应器模式 vs 观察者模式 反应器模式 是一种为处理服务请求并发提交到一个或者多个服务处理程序的事件设计模式.当请求抵达 ...
- selenium 等待时间3种方式
强制等待 sleep() -- 最不建议用 缺点:sleep(10)网络不好的情况,到10秒就抛出异常网络很好,1秒钟就响应了,白白等待多9秒 隐式等待 -- 也不是很理想的方法implicitly_ ...
- EasyUI之DataGrid分页
第一步创建分页DataGrid <table id="dg"> <thead> <tr> <th data-options="f ...
- 使用控制台搭建vue-cli脚手架
注意: 1.安装前您需要查看自己是否有node环境 检查:node - v 2.如果没有的话,需要先搭建好才能进行下一步操作 (参考:https://www.cnblogs.com/sylys/p/ ...
- 基本SQL查询语句
使用Emp表和Dept表完成下列练习 Emp员工表 empno ename job Mgr Hiredate Sal Comm Deptno 员工号 员工姓名 工作 上级编号 受雇日期 薪金 佣金 部 ...