//4_4_1: Error Correction 布尔矩阵奇偶均势特性的保持POJ2260 ZOJ1949
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
int n,i,j,k,row_cnt,col_cnt;
int row[100],col[100],matrix[100][100];
while(cin >> n,n != 0)
{
row_cnt = 0;
col_cnt = 0;
memset(row,0,sizeof(row));
memset(col,0,sizeof(col));
for(i = 0;i < n;i ++)
for(j = 0;j < n; j++)
{
cin >> matrix[i][j];
row[i] += matrix[i][j];
col[j] += matrix[i][j];
}
for(k = 0;k < n;k ++)
{
if(row[k] % 2 == 1) {row_cnt++,i = k;}
if(col[k] % 2 == 1) {col_cnt++,j = k;}
}
if(row_cnt == 0 && col_cnt == 0)
printf("OK\n");
else if(row_cnt == 1 && col_cnt == 1)
printf("Change bit (%d,%d)\n",i + 1,j + 1);
else
printf("Corrupt\n");
}
return 0;
}
/*测试结果:通过POJ2260 ZOJ1949检测
4
1 0 1 0
0 0 0 0
1 1 1 1
0 1 0 1
OK
4
1 0 1 0
0 0 1 0
1 1 1 1
0 1 0 1
Change bit (2,3)
4
1 0 1 0
0 1 1 0
1 1 1 1
0 1 0 1
Corrupt
0
请按任意键继续. . .
*/
POJ2260 ZOJ1949 Error Correction
最新推荐文章于 2019-02-14 14:44:03 发布