Codeforces Round #553 B. Dima and a Bad XOR
题面:
题目描述:
题目分析:

1 #include <cstdio>
2 #include <iostream>
3 #include <cstring>
4 #include <algorithm>
5 using namespace std;
6 int n, m;
7 int G[505][505];
8 struct node{
9 int odd, even;
10 int is;
11 };
12 node row[505];
13
14 int main(){
15 scanf("%d%d", &n, &m);
16 for(int i = 0; i < n; i++){
17 for(int j = 0; j < m; j++){
18 scanf("%d", &G[i][j]);
19 }
20 }
21
22 int t;
23 for(int num = 0; num <= 8; num++){ //枚举结果的位
24 //分类
25 for(int i = 0; i < n; i++){
26 row[i].odd = 0, row[i].even = 0;
27 for(int j = 0; j < m; j++){
28 t = (G[i][j] >> num); //取出整数的第num位
29 if(t & 1) row[i].odd = 1;
30 else row[i].even = 1;
31 }
32 if(row[i].even == 1 && row[i].odd == 1){
33 row[i].is = 2; //第三种情况
34 }
35 else if(row[i].even == 1){
36 row[i].is = 0; //第一种情况
37 }
38 else row[i].is = 1; //第二种情况
39 }
40
41 int flag = 0; //标记
42 int cnt = 0; //统计第一种情况个数
43 for(int i = 0; i < n; i++){
44 if(row[i].is == 1) cnt++;
45 }
46 if(cnt % 2 == 1) flag = 1; //第一种情况为奇数个
47
48 for(int i = 0; i < n; i++){
49 if(row[i].is == 2){ //有符合第三种情况的行,也必定可以产生贡献
50 flag = 1;
51 break;
52 }
53 }
54
55 if(flag) {
56 printf("TAK\n");
57 if(cnt % 2 == 1){
58 for(int i = 0; i < n; i++){
59 if(row[i].is == 2){
60 for(int j = 0; j < m; j++){
61 t = (G[i][j] >> num);
62 if(t % 2 == 0){
63 printf("%d", j+1);
64 break;
65 }
66 }
67 }
68 else printf("%d", 1); //1是随便取的,只要在[1,m]内就行
69
70 //输出格式
71 if(i == n-1) printf("\n");
72 else printf(" ");
73 }
74 }
75 else{
76 int fd = -1;
77 //随便找符合第三种情况的一行,产生贡献
78 for(int i = 0; i < n; i++){
79 if(row[i].is == 2) {
80 fd = i;
81 break;
82 }
83 }
84
85 for(int i = 0; i < n; i++){
86 if(row[i].is == 2){
87 if(i == fd){
88 for(int j = 0; j < m; j++){
89 t = (G[i][j] >> num);
90 if(t % 2 == 1){
91 printf("%d", j+1);
92 break;
93 }
94 }
95 }
96 else{
97 for(int j = 0; j < m; j++){
98 t = (G[i][j] >> num);
99 if(t % 2 == 0){
100 printf("%d", j+1);
101 break;
102 }
103 }
104 }
105 }
106 else printf("%d", 1); //同上
107
108 //输出格式
109 if(i == n-1) printf("\n");
110 else printf(" ");
111 }
112 }
113 return 0;
114 }
115 }
116
117 printf("NIE\n");
118
119 return 0;
120 }
Codeforces Round #553 B. Dima and a Bad XOR的更多相关文章
- Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
- Codeforces Round #553 (Div. 2)
传送门 A. Maxim and Biology 题意: 给出一个串s,问最少需要多少步操作使得串s包含"ACTG"这个子串,输出最少操作次数: 题解: 枚举每个位置 i,求出将 ...
- Codeforces Round #553 (Div. 2) 题解
昨晚深夜修仙上紫记,虽然不错还是很有遗憾的. A. Maxim and Biology 看完就会做的题,然而手速跟不上 #include<cstdio> #include<iostr ...
- Codeforces Round #553 (Div. 2)/codeforces1151
CodeForces1151 Maxim and Biology 解析: 题目大意 每次可以使原串中的一个字符\(+1/-1\),\(Z + 1\to A, A -1\to Z\),求至少修改多少次可 ...
- Codeforces Round #553 (Div. 2)B. Dima and a Bad XOR 思维构造+异或警告
题意: 给出一个矩阵n(<=500)*m(<=500)每一行任选一个数 异或在一起 求一个 异或在一起不为0 的每行的取值列号 思路: 异或的性质 交换律 x1^x2^x3==x3^x2 ...
- Codeforces Round #553 (Div. 2) D题
题目网址:http://codeforces.com/contest/1151/problem/D 题目大意:给出n组数对,(ai , bi),调整这n组数对的位置,最小化 ∑(ai*( i -1)+ ...
- Codeforces Round #553 (Div. 2) C题
题目网址:http://codeforces.com/contest/1151/problem/C 题目大意:给定奇数集和偶数集,现构造一个数组,先取奇数集中一个元素1,再取偶数集二个元素2,4,再取 ...
- Codeforces Round #553 (Div. 2) B题
题目网址:http://codeforces.com/contest/1151/problem/B 题目大意:给定一个n*m的矩阵,问是否可以从每一行中选择一个数,使得这n个数异或大于0,如果可以还要 ...
- Codeforces Round #553 (Div. 2) A题
题目网址:http://codeforces.com/contest/1151/problem/A 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...
随机推荐
- 多线程(二)多线程的基本原理+Synchronized
由一个问题引发的思考 线程的合理使用能够提升程序的处理性能,主要有两个方面, 第一个是能够利用多核 cpu 以及超线程技术来实现线程的并行执行: 第二个是线程的异步化执行相比于同步执行来说,异步执行能 ...
- ysoserial Commons Collections1反序列化研究
Apache Commons Collections1反序列化研究 环境准备 Apache Commons Collections 3.1版本 IDEA 需要一些java基础,反射.类对象.Class ...
- HTML 5.3
HTML 5.3 W3C Working Draft, 18 October 2018 https://www.w3.org/TR/html53/ refs https://www.w3.org/TR ...
- macOS & timer & stop watch
macOS & timer & stop watch https://matthewpalmer.net/blog/2018/09/28/top-free-countdown-time ...
- http cache & 浏览器缓存,存储位置的优先级,条件?
http cache & 浏览器缓存,存储位置的优先级,条件? memory cache disk cache 浏览器缓存,存储位置的优先级,条件, 机制,原理是什么? from memory ...
- how to recursively all files in a folder with sudo permissions in macOS
how to recursively all files in a folder with sudo permissions in macOS write bug OK sudo chmod 777 ...
- yarn create & npx & npm init
yarn create & npx & npm init https://www.npmtrends.com/npm-vs-npx-vs-yarn demo https://www.n ...
- py 时间处理
字符串解析 如果你使用的不是isoformat string那么解析字符串就会失败,需要用strptime转换一下 import datetime datetime.datetime.strptime ...
- SSO & Single Sign On
SSO & Single Sign On 单点登录 https://en.wikipedia.org/wiki/Single_sign-on https://cloud.google.com/ ...
- NGK DeFi Baccarat或将推动BGV成为下一个千倍币!
目前,已经接近2020年年末,但是DeFi的热潮还在持续.近日,DeFi市场传出一道重磅利好消息,便是NGK DeFi去中心化交易系统Baccarat即将上线.届时,将会引起整个区块链市场的又一次震动 ...