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 ...
随机推荐
- 使用PlSQLDeveloper工具查询Oracle会话数
PlSQLDeveloper工具提供了会话管理功能. 能够查询会话内容.杀死会话.查看会话SQL等操作. 常用的会话查询SQL如下: -- 查询所有会话 select * from v$session ...
- A*算法、导航网格、路径点寻路对比(A-Star VS NavMesh VS WayPoint)
在Unity3d中,我们一般常用的寻路算法: 1.A*算法插件 与贪婪算法不一样,贪婪算法适合动态规划,寻找局部最优解,不保证最优解.A*是静态网格中求解最短路最有效的方法.也是耗时的算法,不 ...
- php服务端接收post的json数据
最近用到ext与PHP交互,ext把json数据post给PHP,但在PHP里面$_post获取不到,$_REQUEST也获取不到,但是通过firedebug看到的请求信息确实是把JSON数据post ...
- PHP使用iconv函数遍历数组转换字符集
/** * 字符串/二维数组/多维数组编码转换 * @param string $in_charset * @param string $out_charset * @param mixed $dat ...
- elasticsearch-sql安装
Github地址:https://github.com/NLPchina/elasticsearch-sql elasticsearch-sql插件可以方便我们使用SQL语言来对elasticsear ...
- 移动端1px边框伪类宽高计算
移动端1px边框在手机上看显得比较粗,于是我们用伪类结合css3缩放的方法去设置线条,但是如果设置div的一条边,水平线就设置宽度100%,垂直线就设置高度100%,那么如果是div的四条边呢?宽高1 ...
- PMP项目管理学习笔记(8)——整个管理之监控项目工作、综合变更控制、结束项目或阶段
监控项目工作 输入:企业环境要素.组织过程资产.项目管理计划.绩效报告 工具:专家判断 输出:变更请求.项目管理计划更新.项目文档更新 综合变更控制 输入:企业环境要素.组织过程资产.项目管理计划.变 ...
- 51nod 1031 骨牌覆盖
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 在2*N的一个长方形方格中,用一个1*2的骨牌排满方格. 问有多少种不同的排列方法. 例如: ...
- android studio更新后,构建gradle卡在Refreshing Gradle Project 解决办法
Android Studio每次更新版本都会更新Gradle这个插件,但由于墙的问题,导致更新很慢或者最后更新失败,又是停止在Refreshing Gradle Project ,有时新建项目的时候报 ...
- python调用脚本或shell的方式
python调用脚本或shell有下面三种方式: os.system()特点:(1)可以调用脚本.(2)可以判断是否正确执行.(3)满足不了标准输出 && 错误 commands模块特 ...