ZOJ Problem Set - 1949 Error Correction

来源:互联网 发布:js的display属性 编辑:程序博客网 时间:2024/06/10 13:25
 

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


Source: University of Ulm Local Contest 1998




分析:

题意:

给若干个布尔矩阵,要求判断给定的布尔矩阵是不是具有奇偶性。所谓的奇偶性是指:对于一个n*n的矩阵,它的任何行,列的和都是偶数,这样的矩阵称其为具有奇偶性。如果一个矩阵具有奇偶性,输出OK;否则,如果能够只通过改变一个位置的数字使其具有奇偶性,输出改变的位置。否则,输出corrupt。



对矩阵进行扫描即可,顺便记录下奇数的位置和数量。

简单题。

ac代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=100;
bool a[maxn][maxn];
int s1[maxn],s2[maxn];
int main()
{
    int n,i,j,k;
    while(scanf("%d",&n)&&n)
    {
        memset(s1,0,sizeof(s1));
        memset(s2,0,sizeof(s2));
        for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        {
            scanf("%d",&a[i][j]);
            s1[i]+=a[i][j];
            s2[j]+=a[i][j];
        }
        int c1=0,c2=0;
        int p1,p2;
        for(i=0;i<n;i++)
        {
            if(s1[i]%2)
            {
                c1++;
                p1=i+1;
            }
            if(s2[i]%2)
            {
                c2++;
                p2=i+1;
            }
        }
        if(!c1&&!c2)
        printf("OK\n");
        else if(c1==1&&c2==1)
        {
            printf("Change bit (%d,%d)\n",p1,p2);
        }
        else
        printf("Corrupt\n");
    }


    return 0;
}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 淘宝邮箱忘了怎么办 对方qq邮箱拒收怎么办 邮箱容量满了怎么办 邮箱中转站容量不足怎么办 电脑电源开关坏了怎么办 手机邮箱附件打不开怎么办 台式机电源供电不足怎么办 万能表没电了怎么办 电视电源板坏了怎么办 手机电路板坏了怎么办 iqos主板坏了怎么办 电脑开关没反应怎么办 电子邮件密码忘了怎么办 微信被限制进群怎么办 电子邮箱密码忘了怎么办 qq邮件收不到怎么办 电子邮件密码忘记了怎么办 孩子一烧就39度怎么办 qq邮箱找不到了怎么办 忘记网易邮箱账号怎么办 企业微信用不了怎么办 qq邮箱密码被盗怎么办 企业邮箱密码忘了怎么办 icloud登入不了怎么办 qq邮件加载失败怎么办 收货数量少了怎么办 邮箱附件过期了怎么办 邮箱附件已过期怎么办 163邮箱附件过大怎么办 126邮箱内容过期怎么办 授权码忘记了怎么办 163邮箱忘记账号怎么办 126邮箱忘记账号怎么办 忘记qq登录密码怎么办 崩坏3死邮怎么办 崩坏3死邮箱怎么办 手机邮箱文件打不开怎么办 户口注销后房产怎么办 公司注销后车辆怎么办 注销后的手机号怎么办 网易邮箱修复失败怎么办