Error Correction


Time Limit: 2 Seconds      Memory Limit: 65536 KB

A boolean matrix has the parity property when each row and each column has an even sum, i.e. contains an even number of bits which are set. Here's a 4 x 4 matrix which has the parity property:

1 0 1 0
0 0 0 0
1 1 1 1
0 1 0 1

The sums of the rows are 2, 0, 4 and 2. The sums of the columns are 2, 2, 2 and 2.

Your job is to write a program that reads in a matrix and checks if it has the parity property. If not, your program should check if the parity property can be established by changing only one bit. If this is not possible either, the matrix should be classified as corrupt.

Input

The input will contain one or more test cases. The first line of each test case contains one integer n (n < 100), representing the size of the matrix. On the next n lines, there will be n integers per line. No other integers than 0 and 1 will occur in the matrix. Input will be terminated by a value of 0 for n.

Output

For each matrix in the input file, print one line. If the matrix already has the parity property, print "OK". If the parity property can be established by changing one bit, print "Change bit (i,j)" where i is the row and j the column of the bit to be changed. Otherwise, print "Corrupt".

Sample Input

4
1 0 1 0
0 0 0 0
1 1 1 1
0 1 0 1
4
1 0 1 0
0 0 1 0
1 1 1 1
0 1 0 1
4
1 0 1 0
0 1 1 0
1 1 1 1
0 1 0 1
0

Sample Output

OK
Change bit (2,3)
Corrupt

思路:判断行和列的数和是奇数的个数。

1.如果都是0.那么ok

2.如果都是1,那么可以修改一个,使得ok,用一个变量记录数和是奇数所在的行,用一个变量记录数和是奇数所在的列。

最后输出。

3.其他情况都是Corrupt。

 #include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n;
int i, j;
int NumOfRowOdd, NumOfColOdd, row_index, col_index, sum = ;
int m[][];
while(cin >> n){
if(n == )
break;
NumOfColOdd = ;
NumOfRowOdd = ;
for(i = ; i < n; i++){
for(j = ; j < n; j++){
cin >> m[i][j];
}
}
for(i = ; i < n; i++){
sum = ;
for(j = ; j < n; j++){
sum += m[i][j];
}
if(sum % == ){
NumOfRowOdd++;
row_index = i;
}
}
for(j = ; j < n; j++){
sum = ;
for(i = ; i < n; i++){
sum += m[i][j];
}
if(sum % == ){
NumOfColOdd++;
col_index = j;
}
}
if(NumOfColOdd > || NumOfRowOdd > ){
cout << "Corrupt" << endl;
continue;
}
if(NumOfColOdd == && NumOfRowOdd == ){
cout << "OK" << endl;
continue;
}
printf("Change bit (%d,%d)\n", row_index + , col_index + );
}
return ;
}

最新文章

  1. SharePoint 2016 必备组件离线安装介绍
  2. Android Intent Flags
  3. ELK——Logstash 2.2 mutate 插件【翻译+实践】
  4. php中each()与list()函数
  5. 【Leetcode】 - Divide Two Integers 位运算实现整数除法
  6. Orchard中的多语言功能
  7. Linux系统编程(32)—— socket编程之TCP服务器与客户端
  8. CodeForces 501B - Misha and Changing Handles
  9. 【angular】angular实现简单的tab切换
  10. Query DSL(1)
  11. hashlib,hmac,subprocess,configparser,xlrd,xlwt,xml模块基本功能
  12. 【Dubbo 源码解析】03_Dubbo Protocol&amp;Filter
  13. 谈谈 JavaScript 的正则表达式
  14. Python全栈学习_day004作业
  15. Bootstrap栅栏布局里col-xs-*、col-sm-*、col-md-*、col-lg-*之间的区别及使用方法
  16. Unity中的 原生插件/平台交互 原理
  17. 【转】移除HTML5 input在type=&quot;number&quot;时的上下小箭头
  18. 长期更新系列:C#知识点
  19. BZOJ 2330 糖果 差分约束求最小值
  20. talib 中文文档(七):Overlap Studies Functions

热门文章

  1. 题解报告:hdu 6440 Dream(费马小定理+构造)
  2. linux系统文件目录解析
  3. Apex 使用和学习
  4. sass 常用用法笔记
  5. pre-network android 网络优化预加载框架
  6. JDBC的fetchsize和maxrows
  7. AS400服务程序总结
  8. centos下升级python
  9. node.js中使用Redis
  10. PyTorch如何构建深度学习模型?