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 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...
随机推荐
- 2.使用Helm构建ElasticSearch集群
作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-05-24 16:08:53 星期五 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ...
- Linux系统诊断必备技能之二:日志查询常用命令详解
一.概述 日常运维工作中,排查线上环境问题,少不了去线上查日志.而使用什么命令,能快速准确地查到我们需要查找地日志信息,也是我们需要掌握的一项技能.下面介绍一下日常工作常用到的查看日志命令:tail, ...
- TCP之“3次握手,4次挥手”问题
你知道"3次握手,4次挥手"吗? 当面试官问你什么是"3次握手,4次挥手",你是不是要开启"诵经"模式了?作为程序员,要有"刨根问 ...
- Postman查看上传文件过程时出现400 - Required MultipartFile parameter 'files' is not present错误
我在利用postman查看上传图片文件时,出现了如下图的错误,看到之后很懵逼. 图1 上网搜了一下,归结下来就是参数不一致导致的.不过还有一些是由于没加注解,如下图示: 图2 关于参数不一致问题,主要 ...
- 2017CCCC决赛 L1-3. 阅览室
L1-3 阅览室(20 分) 天梯图书阅览室请你编写一个简单的图书借阅统计程序.当读者借书时,管理员输入书号并按下S键,程序开始计时:当读者还书时,管理员输入书号并按下E键,程序结束计时.书号为不超过 ...
- 【php代码审计】熊海cms1.0
0x01 环境安装 1. 熊海cms1.0 (http://js.down.chinaz.com/201503/xhcms_v1.0.rar) 2.seay代码审计工具 3. phpstudy (ph ...
- pikachu-反射性xss(get)
首先打开漏洞网页,发现输入的长度好像被限制了, 我们便F12查看源代码,发现长度被限制成了20,而且还是前端验证的,我们可以直接修改为100 在我们的输入框中,输入 <script>ale ...
- 翻译:《实用的Python编程》01_05_Lists
目录 | 上一节 (1.4 字符串) | 下一节 (1.6 文件) 1.5 列表 本节介绍 Python 原始数据类型列表(list). 列表是一种有序的集合. 创建列表 使用方括号 [] 来定义列表 ...
- js currying All In One
js currying All In One 柯里化 refs https://juejin.im/post/6844903603266650125 xgqfrms 2012-2020 www.cnb ...
- js console.log color all in one
js console.log color all in one console.log color Chrome console.log 语法 / grammar %c, %s, css style ...