题目描述

我们有一个 n * m 的矩阵,
现在我会告诉你每一行和每一列的异或和
请求出任意一种可能的矩阵

数据范围

1<=n,m<=100
输入数据确保在int范围内

输入输出格式:

输入格式:

第一行:两个整数 n,m
第二行:n 个整数,表示每一行的异或和
第三行:m 个整数,表示每一列的异或和

输出格式:

一个满足以上条件的 n * m 的矩阵

样例

输入


输出

YES

解题思路

这是一道比较好的构造题,考虑构造好的矩阵转化成二进制位,相当于我们只需要构造一个01矩阵

那么我们先将左上角(n-1)*(m-1)先填上,后面直接利用异或和出解即可

AC Code

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<iostream>
#define ll long long
#define N 101
using namespace std;
int n,m,g[N][N],a[N],b[N];
int main() {
cin>>n>>m;
for(int i=; i<=n; ++i)cin>>a[i];
for(int i=; i<=m; ++i)cin>>b[i];
for(int i=; i<; ++i) {
for(int j=; j<n; ++j)
for(int k=; k<m; ++k)g[j][k]|=<<i;
int s1=,s2=;
for(int j=; j<n; ++j)
if(((m-)&)^((bool)(a[j]&(<<i))))s1^=,g[j][m]|=<<i;
for(int j=; j<m; ++j)
if(((n-)&)^((bool)(b[j]&(<<i))))s2^=,g[n][j]|=<<i;
if((((bool)(b[m]&(<<i)))^s1)!=(((bool)(a[n]&(<<i)))^s2)) {
puts("NO");
exit();
}
if(((bool)(b[m]&(<<i)))^s1)g[n][m]|=<<i;
}
puts("YES");
for(int i=; i<=n; ++i,puts(""))
for(int j=; j<=m; ++j)printf("%d ",g[i][j]);
return ;
}

CF1016D Vasya And The Matrix的更多相关文章

  1. CF 1042 E. Vasya and Magic Matrix

    E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...

  2. 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 ...

  3. codeforces1016 D. Vasya And The Matrix(思维+神奇构造)

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. D. Vasya And The Matrix(Educational Codeforces Round 48)

    D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandar ...

  5. Vasya And The Matrix CodeForces - 1016D (思维+构造)

    Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the ma ...

  6. 【CF1016D】Vasya And The Matrix(构造)

    题意: 思路:构造方式见代码…… #include<cstdio> #include<cstring> #include<iostream> #include< ...

  7. CF1016 D. Vasya And The Matrix

    传送门 [http://codeforces.com/group/1EzrFFyOc0/contest/1016/problem/D] 题意 已知矩阵n行m列,以及每一行,每一列所有元素的异或,用 a ...

  8. CodeForces - 1016D Vasya And The Matrix

    题面在这里! 很明显二进制每一位都是无关的,所以可以先把原问题简化:给矩阵中的每个位置填入0/1,使得特定行/列有奇数个1,其他行/列有偶数个1. 一个比较好想的方法是对行和列 列出 n+m 个异或方 ...

  9. CF1042E Vasya and Magic Matrix

    感觉不会期望. 首先把所有格子按照权值从小到大排一下序,这样一共有$n * m$个元素,每个元素有三个属性$x, y, val$. 下文中的下标均为排序后的下标. 这样子我们就可以推出公式: $f_i ...

随机推荐

  1. LeetCode 931. Minimum Falling Path Sum

    原题链接在这里:https://leetcode.com/problems/minimum-falling-path-sum/ 题目: Given a square array of integers ...

  2. Guava com.google.common.base.Stopwatch Spark程序在yarn中 MethodNotFound

    今天在公司提交一个Spark 读取hive中的数据,写入JanusGraph 的app,自己本地调试没有问题,放入环境中提交到yarn 中时,发现app 跑不起. yarn 中日志,也比较明显,app ...

  3. python 数据分析

    pandas 格式化数据的读取 numpy 提供数组处理,类似matlap matplotlib 数据可视化 https://www.cnblogs.com/5poi/p/7148000.html

  4. BZOJ 5507: [gzoi2019]旧词 LCT

    和之前那个 [LNOI]LCA 几乎是同一道题,就是用动态树来维护查分就行. code: #include <bits/stdc++.h> using namespace std; #de ...

  5. learning scala list.collect

    collect will apply a partial function to all elements of a Traversable and return a different collec ...

  6. 自助法(Bootstraping)

    自助法(Bootstraping)是另一种模型验证(评估)的方法(之前已经介绍过单次验证和交叉验证:验证和交叉验证(Validation & Cross Validation)).其以自助采样 ...

  7. sublime text 3 安装、添加命令行启动、汉化、注册码

    1. 安装sublime: 下载:http://www.sublimetext.com/3 添加命令行启动:设置环境变量->计算机->右键属性->高级系统设置->环境变量-&g ...

  8. GoCN每日新闻(2019-10-11)

    GoCN每日新闻(2019-10-11) GoCN每日新闻(2019-10-11) 1. golang 将数据库转换为gorm结构 https://studygolang.com/articles/2 ...

  9. 让你的shell更体贴

    使用shell的时候很多,特别是拉幕式终端,使用时更加方便,同时可以利用 echo "Did you know that:" ;whatis $(ls /bin | shuf -n ...

  10. 记录python循环引用带来的MemoryError错误解决

    在以前的python中,没有遇到过这样的错误,上来之后还是很蒙蔽的,问了几个业内的人,他们 都给我说让我改服务器里面配置的东西, 因为是要给大家用的,服务器要保证长久运行,不能临时去修改这个,导致在大 ...