CF1208C
CF1208C
这场杜老师大战tourist的比赛怎么这么多人类智慧题。。。
题意:
构造一个 $ n \times n $ 的矩阵,使得该矩阵每一行与每一列的元素的异或和全部相等。
解法:
异或的神奇应用系列。
因为 $ n $ 一定是4的倍数,所以考虑2进制,一定是每4位是一个整体。
现在,为了使矩阵中的数字不同,将数字乘以4.分别在第1,第2和第3位置中添加1,2和3。 每行和每列的XOR仍将保持为0。
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
#define N 1010
int a[N][N],n,cnt;
int main() {
scanf("%d",&n);
for(int i = 1 ; i <= n / 2 ; i++) {
for(int j = 1 ; j <= n / 2 ; j++) {
a[i][j] = cnt * 4;
a[i][j + n / 2] = cnt * 4 + 1;
a[i + n / 2][j] = cnt * 4 + 2;
a[i + n / 2][j + n / 2] = cnt * 4 + 3;
cnt++;
}
}
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
printf("%d ",a[i][j]);
puts("");
}
}
//system("pause");
return 0;
}
CF1208C的更多相关文章
随机推荐
- JVM内存结构划分
JVM内存结构划分 JVM内存结构划分 数据区域划分 程序计数器 虚拟机栈 本地方法栈 堆 方法区 运行时常量池 StringTable 直接内存 创建新对象说明 对象的创建 对象的内存布局 对象头 ...
- ajax简单页面
简单的注册页面运用ajax 主页面 <head><meta http-equiv="Content-Type" content="text/html; ...
- php文件包含漏洞 file inclusion vulnerability
0x00 何为文件包含漏洞 开发人员如果在写类似include "a.php"的代码时,如果将a.php写成了可变的值,那么就可以在上面做文章,举个理想的例子: <? inc ...
- Array + two points leetcode.16 - 3Sum Closest
题面 Given an array nums of n integers and an integer target, find three integers in nums such that th ...
- 6.显示锁Lock 和 线程通信Condition
显示锁 Lock 一.用于解决多线程 安全问题的方式: synchronized: 1.同步代码块 2.同步方法 jdk1.5 后:第三种:同步锁Lock (注意:同步(synchro ...
- el-table——可编辑拖拽转换csv格式的表格
<!--可拖拽的表格:表格内容+行参数+按钮名称(对话框标题)--> <template> <div> <el-button size="mini& ...
- nginx屏蔽版本号
nginx的http段添加 server_tokens off; 在nginx.conf文件内如上增加server_tokens off;就隐藏了
- 7.MapReduce操作Hbase
7 HBase的MapReduce HBase中Table和Region的关系,有些类似HDFS中File和Block的关系.由于HBase提供了配套的与MapReduce进行交互的API如 Ta ...
- I2C总线、设备、驱动
I2C总线.设备.驱动 框架 I2C驱动框架可分为3个部分,分别是:I2C核心层.I2C总线驱动层(适配器层)以及I2C设备驱动层: I2C核心层 提供了统一的I2C操作函数,主要有两套函数smbus ...
- Mha-Atlas-MySQL高可用方案实践
一,mysql-mha环境准备 1.1 实验环境: 1.1 实验环境: 主机名 IP地址(NAT) 描述 mysql-master eth0:10.1.1.154 系统:CentOS6.5(6.x都可 ...