POJ 2260:Error Correction
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6014 | Accepted: 3886 |
Description
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
Input will be terminated by a value of 0 for n.
Output
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
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <iostream>
using namespace std;
int main()
{
int a[105][105],b[105],c[105],i,j,n;
while(cin >> n,n)
{
for(i = 0; i<n; i++)
for(j = 0; j<n; j++)
cin >> a[i][j];
for(i = 0; i<n; i++)
{
b[i] = 0;
for(j = 0; j<n; j++)
b[i]+=a[i][j];
}
for(i = 0; i<n; i++)
{
c[i] = 0;
for(j = 0; j<n; j++)
c[i]+=a[j][i];
}
int sum1=0,sum2 = 0,flag1,flag2;
for(i = 0; i<n; i++)
if(b[i]%2)
sum1++,flag1 = i;
for(i = 0; i<n; i++)
if(c[i]%2) sum2++,flag2 = i;
if(sum1 > 1 || sum2>1)cout << "Corrupt" << endl;
else if(!sum1 && !sum2)cout << "OK" << endl;
else cout << "Change bit (" << flag1+1 << "," << flag2+1 << ")" << endl;
}
return 0;
}
POJ 2260: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 增加冗余包,当无线等网络丢包之后,接 ...
- zoj 1949 Error Correction
Error Correction Time Limit: 2 Seconds Memory Limit: 65536 KB A boolean matrix has the parity p ...
- 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, ...
- POJ 2260
#include <iostream> #define MAXN 100 using namespace std; int _m[MAXN][MAXN]; int main() { //f ...
- [ipsec][strongswan] VirtualPN隧道网络加速FEC(forward error correction)
引用 跟一个网友就有关IPsec的网络加速以及降低延迟等问题进行了一些讨论,并总结了一写粗浅的看法. 因为FEC的资料并不多,所以分享出来,希望能被有需要的人看见:) 先说一下FEC. 我们使用ips ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
随机推荐
- 【牛客小白月赛6】 J 洋灰三角 - 快速幂&逆元&数学
题目地址:https://www.nowcoder.com/acm/contest/136/J 解法一: 推数学公式求前n项和: 当k=1时,即为等差数列,Sn = n+pn(n−1)/2 当k≠1时 ...
- POJ 1149 PIGS 建图,最大流
题意: 你m个猪圈以及每个猪圈里原来有多少头猪,先后给你n个人,每个人能打开某一些猪圈并且他们最多想买Ki头猪,在每一个人买完后能将打开的猪圈中的猪顺意分配在这次打开猪圈里,在下一个人来之前 已打开的 ...
- 笔试算法题(51):简介 - 红黑树(RedBlack Tree)
红黑树(Red-Black Tree) 红黑树是一种BST,但是每个节点上增加一个存储位表示该节点的颜色(R或者B):通过对任何一条从root到leaf的路径上节点着色方式的显示,红黑树确保所有路径的 ...
- linux纯字符界面不支持中文
[2017-01-17] linux纯字符界面不支持中文
- Spider-scrapy日志处理
Scrapy生成的调试信息非常有用,但是通常太啰嗦,你可以在Scrapy项目中的setting.py中设置日志显示等级: LOG_LEVEL = 'ERROR' 日志级别 Scrapy日志有五种等级, ...
- 关于.NET玩爬虫这些事 【初码干货】
这几天在微信群里又聊到.NET可以救中国但是案例太少不深的问题,我说.NET玩爬虫简直就是宇宙第一,于是大神朱永光说,你为何不来写一篇总结一下? 那么今天就全面的来总结一下,在.NET生态下,如何玩爬 ...
- servlet页面没有跳转
Boolean b = userService.selectByParams(user);if (b) { req.getSession().setAttribute("loginname& ...
- POJ 1330 (LCA)
http://poj.org/problem?id=1330 题意:给出一个图,求两个点的最近公共祖先. sl :水题,贴个模板试试代码.本来是再敲HDU4757的中间发现要用LCA, 操蛋只好用这 ...
- LOJ#541. 「LibreOJ NOIP Round #1」七曜圣贤
有一辆车一开始装了编号0-a的奶茶,现有m次操作,每次操作Pi在[-1,b),若Pi为一个未出现过编号的奶茶,就把他买了并装上车:若Pi为一个在车上的奶茶,则把他丢下车:否则,此次操作为捡起最早丢下去 ...
- mysql控制流程函数(case,if,ifnull,nullif)
1.case...when... 用法 参考:http://www.cnblogs.com/qlqwjy/p/7476533.html CASE value WHEN [compare-value] ...