ZOJ Problem Set - 1949 Error Correction
来源:互联网 发布:js的display属性 编辑:程序博客网 时间:2024/06/10 13:25
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;
}
- ZOJ Problem Set - 1949 Error Correction
- ZOJ Problem Set - 1949 Error Correction
- ZOJ Problem Set - 1949 Error Correction
- zoj 1949 Error Correction
- zoj 1949 Error Correction
- ZOJ 1949Error Correction
- zoj 1949 Error Correction
- ZOJ 1949 Error Correction
- zoj 1949 Error Correction
- ZOJ 1949 Error Correction
- Error Correction(zoj 1949)
- zoj 1949 Error Correction
- zoj 1949.Error Correction
- zoj 1949 Error Correction(题号是建国1949哈~~)
- POJ 2260(ZOJ 1949) Error Correction 一个水题
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 1037
- C语言编程(练习3:函数 )
- FAQ04298 首次开机,自动安装预置APK
- 常见验证码的弱点与验证码识别
- zstack定位程序的学习(3)--盲节点程序解读
- (转载) C++ ofstream和ifstream详细用法
- ZOJ Problem Set - 1949 Error Correction
- 自定义拦截器获取不到action中的数据
- View的onDraw函数
- 零售系统软件架构---设计之权限数据分发
- 数据挖掘:FP增长
- 2014百度之星初赛第二轮代码注释:Best_Financing
- javax.servlet.jsp.*和javax.servlet.http.*
- BZOJ 2127 happiness 最小割
- 行指针和列指针详解