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 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...
随机推荐
- Ubuntu16安装chrome
不免让您失望, 安装正常的chrome,Dependency is not satisfiable: libnss3 (>= 2:3.22)问题一直没能解决,故使用chromium次而代之. s ...
- 微信公众号代码高亮美化工具 All In One
微信公众号代码高亮美化工具 All In One markdown 美化 mdnice 编辑器 https://www.mdnice.com/ https://github.com/mdnice ma ...
- Generator function vs Async/Await
Generator function vs Async/Await generator async /await refs xgqfrms 2012-2020 www.cnblogs.com 发布文章 ...
- PHP & LAMP & WAMP
PHP & LAMP & WAMP https://github.com/xgqfrms/DataStructure/issues/7#issuecomment-430538438 h ...
- github & code owners
github & code owners https://help.github.com/en/github/creating-cloning-and-archiving-repositori ...
- ng mock服务器数据
angualr文档 in-memory-web-api 文档 安装 yarn add angular-in-memory-web-api -S src/app/app.module.ts import ...
- Android 比较好看的注册登录界面
各位看官姥爷: 对于一款android手机app而言,美观的界面使得用户有好的使用体验,而一款好看的注册登录界面也会给用户好的用户体验,那么话不多说,直接上代码 首先是一款简单的界面展示 1.登陆界面 ...
- C++算法代码——[TYVJ]单数?双数?
题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=1178 题目描述 Bessie那惨无人道的二年级老师搞了一个有 N (1 < ...
- IDEA重新安装之后配置GIT
注:此方法可用于配置gitlab也可用于配置github 1.在github中创建一个账号:https://github.com/join?source=header-home 2.下载并安装git: ...
- Aliyun Oss 上传文件
目录 Aliyun OSS OSS 简介 OSS 基本概念 OSS 功能概述 OSS 使用 创建存储空间Bucket 创建子目录 Java编码 测试 Aliyun OSS OSS 简介 阿里云对象存储 ...