【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
【链接】 我是链接,点我呀:)
【题意】
告诉你每一行、每一列的异或和。
让你求出一个符合要求的原矩阵。
【题解】
显然应该有
a1^a2^....^an = b1^b2^....^bn
也即两边同时异或一下a1^b1
b1^a2^a3...^an =a1^b2^...^bn
我们设x=b1^a2^a3...^an =a1^b2^...^bn
然后我们就能得到一个符合要求的矩阵了

会发现第一列的异或和就是b1.第一行的异或和就是a1
因为x同时可以写成上面的那两种形式
第2到第n行以及第2到第m列显然也是满足要求的,下面全是0了
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define res(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N =1000000;
LL m,n,arr[N+10],brr[N+10],ans[1000][1000];
int main()
{
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n>> m;
int a=0,b=0;
for (int i = 0; i < n; i++)
{
cin >>arr[i];
if(i!=0) a=a^arr[i];
}
for (int i = 0; i < m; i++)
{
cin >>brr[i];
if(i!=0) b=b^brr[i];
}
a=a^brr[0];
b=b^arr[0];
if(a!=b){
cout << "NO" <<endl;
return 0;
}
rep1(i,0,n-1){
rep1(j,0,m-1){
if(i==0&&j==0) ans[i][j]=a;
else if(i==0)
{
ans[i][j]=brr[j];
}
else if(j==0)
{
ans[i][j]=arr[i];
}
}
}
cout << "YES" <<endl;
rep1(i,0,n-1){
rep1(j,0,m-1){
if(j!=0) cout << " ";
cout <<ans[i][j] ;
}
cout << endl;
}
return 0;
}
【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix的更多相关文章
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
- 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot
[链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...
- Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement
[链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 48 (Rated for Div. 2)
http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法 为什么我做了那么多讨论,原 ...
- Educational Codeforces Round 48 (Rated for Div. 2) B 1016B Segment Occurrences (前缀和)
B. Segment Occurrences time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
随机推荐
- vim 插件配置博客记录
本来打算自己写下各种经常使用vim的插件安装方法, 可是搜索了下, 发现别人都写过了, 在写一遍也没有意思, 特此记录. Vim 经常使用命令 http://blog.csdn.net/hittata ...
- 零基础学python-2.16 列表解析
这一节聊聊强大的列表解析 主要就是在一行里面赋值给列表 以下我们举两个样例: 上面的样例我们引入了range函数,他主要作用是在一定范围里面取整数值 我来解释一下中括号中面的那一句:x**2 for ...
- 杭电1879继续畅通project
继续畅通project Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 【cl】maven新建web项目
我的环境:window32位 +jdk1.7.0_75+maven3.3.3 1.ctrl+N 新建maven project项目 2.选择maven-archetype-webapp [这里一开始用 ...
- iOS关于iPhone6和iPhone6 Plus的屏幕适配问题
iPhone6和iPhone6 Plus上市有一段时间了.尽管大陆没有首发令人隐隐作痛,可是还是为iPhone6和iPhone6 Plus的设计的转变和大屏时代感到欣喜. 今天主要来mark下面通过x ...
- 11gR2 Database Services for "Policy" and "Administrator" Managed Databases (文档 ID 1481647.1)
In this Document Purpose _afrLoop=1459311711568804&id=1481647.1&displayIndex=6&_afrW ...
- 消息推送之百度云推送Android集成与用法
这两天因为项目须要.研究了一下百度云推送,本来这事没什么多大工作量的,但注冊百度开发人员账户创建应用令我蛋疼菊紧了好一阵,这些东西做了对技术没啥提升,不做又不行,必经之路. 好在我耗费了N多个毫毫秒秒 ...
- Qt中暂停线程的执行(主线程和工作线程共用一把锁,一旦主线程将它锁上,工作线程就无法运行了,这也是一个办法)
在线程中定义一个信号量: QMutex pause; 把run()函数中循环执行的部分用信号量pause锁住: void run() { while(1) { pause.lock ...
- 关于Mybatis的几个问题
今天在用mybatis开发的时候遇到两个问题,下面一一列出并给出解决方案. 问题一 最开始我设置的实体类中有个字段如isParent为boolean类型,set和get方法是eclispe自动生成的. ...
- Nginx 配置埋点js日志采集
页面埋点&nginx日志采集 页面(web容器:httpd/nginx负载均衡 + apache server)<===> 日志采集服务器(nginx服务器) 通过某个页面跳转到我 ...