Educational Codeforces Round 48 (Rated for Div. 2) D. Vasya And The Matrix(思维/构造)
程序员文章站
2022-04-27 11:34:44
...
D. Vasya And The Matrix
emmm,想不出来C,最后15mins溜出来写个D的题解● 3●
题意:给你每行每列的异或让你去构造这个矩阵.
其实很简单,首先我们可以发现n和m都很小,那么排除算法题,肯定是往暴力的方向想。
那么我们暴力什么呢?题目给的是连续异或,那么最后结果的每一位的0/1肯定是取决于原矩阵对应行每个数对应位的0或者1的和奇偶。
那么就很简单啦,暴力每个数的每一个二进制位,看最后是否能符合奇偶关系构造出来就好啦.
代码也很简洁,应该.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
ll a[105];
ll b[105];
ll r[105];
ll c[105];
ll mi[105][105];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=m;i++) scanf("%lld",&b[i]);
memset(mi,0,sizeof(mi));
for(int i=0;i<32;i++)
{
for(int j=1;j<=n;j++) r[j]=(a[j]>>i)&1;
for(int j=1;j<=m;j++) c[j]=(b[j]>>i)&1;
int flag=0;
for(int j=1;j<n;j++)
{
if(r[j]) flag^=1,mi[j][m]|=(1<<i);
}
// flag=0;
int flag2=0;
for(int j=1;j<m;j++)
{
if(c[j]) flag2^=1,mi[n][j]|=(1<<i);
}
if(flag==c[m]&&flag2==r[n]) continue;
if(flag^1==c[m]&&flag2^1==r[n]) mi[n][m]|=(1<<i);
else return printf("NO\n")*0;
}
printf("YES\n");
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) printf("%lld ",mi[i][j]);
printf("\n");
}
}
上一篇: 【树】B040_LC_节点与其祖先之间的最大差值(后序遍历)
下一篇: 二叉搜索树的后序遍历序列
推荐阅读
-
Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree
-
Educational Codeforces Round 60 (Rated for Div. 2) ----A - Best Subsegment(思维题)
-
D. Sequence and Swaps(模拟+枚举) Educational Codeforces Round 99 (Rated for Div. 2)
-
Educational Codeforces Round 91 (Rated for Div. 2) D. Berserk And Fireball
-
Educational Codeforces Round 83 (Rated for Div. 2) D. Count the Arrays
-
Codeforces Educational Codeforces Round 80 (Rated for Div. 2) E - Messenger Simulator(树状数组+思维)
-
Codeforces Raif Round 1 (Div. 1 + Div. 2) D. Bouncing Boomerangs(思维+构造)
-
Educational Codeforces Round 43 (Rated for Div. 2) D. Degree Set
-
Educational Codeforces Round 55 (Rated for Div. 2) D. Maximum Diameter Graph (构造图)
-
Educational Codeforces Round 49 (Rated for Div. 2)-D. Mouse Hunt