zoj 1949 Error Correction
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的更多相关文章
- POJ 2260 Error Correction 模拟 贪心 简单题
Error Correction Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6825 Accepted: 4289 ...
- FEC(Forward Error Correction)前向纠错 UDP\RTP 中使用用于改善无线等网络丢包等问题--转
FEC(Forward Error Correction)前向纠错 UDP\RTP 中使用用于改善无线等网络丢包等问题 算法暂不介绍. 思路:FEC ENCODE 增加冗余包,当无线等网络丢包之后,接 ...
- POJ 2260:Error Correction
Error Correction Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6014 Accepted: 3886 ...
- QR Code Error Correction
QR Code Error Correction - QRStuff.com https://blog.qrstuff.com/2011/12/14/qr-code-error-correction ...
- POJ 2260(ZOJ 1949) Error Correction 一个水题
Description A boolean matrix has the parity property when each row and each column has an even sum, ...
- [ipsec][strongswan] VirtualPN隧道网络加速FEC(forward error correction)
引用 跟一个网友就有关IPsec的网络加速以及降低延迟等问题进行了一些讨论,并总结了一写粗浅的看法. 因为FEC的资料并不多,所以分享出来,希望能被有需要的人看见:) 先说一下FEC. 我们使用ips ...
- ECC(Error Checking and Correction)校验和纠错
ECC的全称是 Error Checking and Correction or Error correction Coding,是一种用于差错检测和修正的算法.上一节的BBM中我们提到过,NAND闪 ...
- [IR] Tolerant Retrieval & Spelling Correction & Language Model
Dictionary不一定是个list,它可以是多种形式. 放弃Hash的原因: 通常,tree是比较适合的结构. From: http://www.cnblogs.com/v-July-v/arch ...
- COM Error Code(HRESULT)部分摘录
Return value/code Description 0x00030200 STG_S_CONVERTED The underlying file was converted to compou ...
随机推荐
- 1-17finally关键字
finally的特点 被finally控制的语句体一定会执行,除非在执行finally语句体之前JVM退出(比如System.exit(0)),一般用于关闭资源 finally如何使用? finall ...
- PHP fgets 函数
<?php $handle=fopen("../good/html/1.txt","r"); ; //打开一个远程文件 $content="&q ...
- json2.js 源码解读
这一部分是对Date String Number Boolean扩展toString方法,Date的toString是返回UTC格式的字符串,而后面几个是返回原始值. function f(n) {/ ...
- ISCSI存储
slave-147作为服务端 需要安装的软件 [root@slave-147 ~]# yum install -y scsi-target-utils slave-148和slave-149作为客户端 ...
- RHEL6.5、RHEL7.2忘记ROOT密码恢复小结
RHEL6.5忘记root密码恢复步骤 RHEL7.2恢复密码步骤 5.耐心等待重启完成即可实现重置root密码 也可以按如下做法 依次执行chroot /sysroot/,passwd===> ...
- 百度地图API简单初始化
<script src="http://api.map.baidu.com/api?key=&v=2.0&ak=youkey"></script& ...
- oracle 权限、规则
Oracle中关于权限与规则简单总结: --1,管理员登录 conn sys/orcl@orcl as sysdba; --2,创建用户方案---必须管理员身份才能操作 create user use ...
- 2019/05/11 JAVA虚拟机原理堆、栈、方法区概念区别
Java堆 堆内存用于存放由new创建的对象和数组.在堆中分配的内存,由java虚拟机自动垃圾回收器来管理.在堆中产生了一个数组或者对象后,还可以在栈中定义一个特殊的变量,这个变量的取值等于数组或者对 ...
- 你有学习者综合征吗?Web 开发是重灾区
[导读]:学习者综合征的主要表现:学而不用,不停学习,却没有真正实际应用知识来做东西.如果过去的一年里,学习的语言或框架超过三个,那可能已经感染学习者综合征了.Web 开发是重灾区咯. 你有学习者综合 ...
- Linux系统结构与终端控制台
Linux系统结构与终端控制台 作者:Vashon 时间:20150418 以下主要是对Linux系统终端控制台切换及基本操作的范例,其他的理论就不多说了,直接进入实践部分. Starting.... ...