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 ;
}

zoj 1949 Error Correction的更多相关文章

  1. POJ 2260 Error Correction 模拟 贪心 简单题

    Error Correction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6825   Accepted: 4289 ...

  2. FEC(Forward Error Correction)前向纠错 UDP\RTP 中使用用于改善无线等网络丢包等问题--转

    FEC(Forward Error Correction)前向纠错 UDP\RTP 中使用用于改善无线等网络丢包等问题 算法暂不介绍. 思路:FEC ENCODE 增加冗余包,当无线等网络丢包之后,接 ...

  3. POJ 2260:Error Correction

    Error Correction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6014   Accepted: 3886 ...

  4. QR Code Error Correction

    QR Code Error Correction - QRStuff.com https://blog.qrstuff.com/2011/12/14/qr-code-error-correction ...

  5. POJ 2260(ZOJ 1949) Error Correction 一个水题

    Description A boolean matrix has the parity property when each row and each column has an even sum, ...

  6. [ipsec][strongswan] VirtualPN隧道网络加速FEC(forward error correction)

    引用 跟一个网友就有关IPsec的网络加速以及降低延迟等问题进行了一些讨论,并总结了一写粗浅的看法. 因为FEC的资料并不多,所以分享出来,希望能被有需要的人看见:) 先说一下FEC. 我们使用ips ...

  7. ECC(Error Checking and Correction)校验和纠错

    ECC的全称是 Error Checking and Correction or Error correction Coding,是一种用于差错检测和修正的算法.上一节的BBM中我们提到过,NAND闪 ...

  8. [IR] Tolerant Retrieval & Spelling Correction & Language Model

    Dictionary不一定是个list,它可以是多种形式. 放弃Hash的原因: 通常,tree是比较适合的结构. From: http://www.cnblogs.com/v-July-v/arch ...

  9. COM Error Code(HRESULT)部分摘录

    Return value/code Description 0x00030200 STG_S_CONVERTED The underlying file was converted to compou ...

随机推荐

  1. sublime text 3 文件列表忽略特定格式的文件

    Preferences->Settings ,编辑相关代码,注意JSON格式: 排除特定目录,使用:"folder_exclude_patterns" 排除特定文件,使用:& ...

  2. POM报错Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from

    解决方式一:   1.查看.m2\repository\org\apache\maven\plugins\maven-resources-plugin\下maven-resources-plugin- ...

  3. 转--v$session & v$process各字段的说明【转载】

    Oracle 动态性能表 v$session & v$process 整理自google出来的网络资源.google是个好东东.没有google我会心神不宁. v$session SADDR: ...

  4. 转 PHP文件上传$_FILES数组各键值含义说明

    文件上传的html表单: <form enctype="multipart/form-data" action="" method="POST& ...

  5. 利用layui的load模块解决图片上传

    首先肯定要参考layui官网的upload模块文档:http://www.layui.com/doc/modules/upload.html 讲讲思路:在一份添加表单中,我们有个图片上传的模块,然后我 ...

  6. Super Mario 树状数组离线 || 线段树

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. Hadoop体系结构管理

    一.查看Zookeeper信息 [hadoop@weekend01 ~]$zkServer.sh status JMX enabled by default Using config: /hadoop ...

  8. ping localhost 返回 ::1的导致不能打开http://localhost的原因及解决

    虽然可以在浏览器中正常访问http://localhost但用file,file_get_contents等函数打开http://localhost异常.用127.0.0.1也可以打开,本地hosts ...

  9. empty 和 isset的区别和联系

    empty 和 isset的区别和联系 要说它们的联系,其共同点就是empty()和isset()都是变量处理函数,作用是判断变量是否已经配置,正是由于它们在处理变量过程中有很大的相似性,才导致对它们 ...

  10. 2. UITest相关APIs

    1. XCUIApplication 这是你正在测试的应用的代理.它能让你启动应用,这样你就能执行测试了.它每次都会新起一个进程,这会多花一些时间,但是能保证测试应用时的状态是干净的,这样你需要处理的 ...