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 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...
随机推荐
- npm-run-all
npm-run-all npm scripts https://www.npmjs.com/package/npm-run-all A CLI tool to run multiple npm-scr ...
- Base 64 & URL & blob & FileReader & createObjectURL
Base 64 & URL & blob & FileReader & createObjectURL /** * let blob = item.getAsFile( ...
- array auto slice
array auto slice https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Ar ...
- py 时间处理
字符串解析 如果你使用的不是isoformat string那么解析字符串就会失败,需要用strptime转换一下 import datetime datetime.datetime.strptime ...
- NGK数字增益平台中如何分配代币产出
最近很多朋友听说NGK公链的主网和数字增益平台即将上线以后都纷纷表示非常感兴趣,已经基本了解了NGK代币的产出方式,但还是对代币产出分配的问题不是很明确.今天小编就给大家科普一下,NGK代币在NGK数 ...
- 20_MySQL表的内连接实操
-- 查询底薪超过公司平均底薪的员工信息 -- 方法1 SELECT empno,ename FROM t_emp HAVING sal>AVG(sal); 因为在having中不能拿一个字段与 ...
- 整合shiro+jwt大体思路
springboot整合shiro大体上的思路: 1.自定义一个类Realm extends AuthorizingRealm{} 主要是对token授权和认证 重写2个方法 doGetAuthori ...
- python进阶(1)Lambda表达式
Lambda表达式 lambda表示的是匿名函数,不需要用def来声明,一句话就可以声明出一个函数 语法 函数名 = lambda 参数:返回值 注意点 1.函数的参数可以有多个,多个参数之间用逗号隔 ...
- CentOS7安装Kibana7.9.2
1:下载 wget https://artifacts.elastic.co/downloads/kibana/kibana-7.9.2-linux-x86_64.tar.gz 点击进入官网 安装手册 ...
- MYSQL bin_log 开启及数据恢复
参考博客: A:https://www.jianshu.com/p/55b0d52edca2 B:https://www.cnblogs.com/martinzhang/p/3454358.html ...