Error Correction
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6825   Accepted: 4289

Description

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的数量,看奇数个的交叉点,大于一个或没有则不能实现。

#include<stdio.h>

int main()
{
int a[105][105];
int n;
while (~scanf("%d", &n))
{
int i, j;
int num1 = 0,num2=0;
if (!n)
{
break;
}
int x, y;
for ( i = 1; i <= n; i++)
{
int sum = 0;
for ( j = 1; j <= n; j++)
{
scanf("%d", &a[i][j]);
sum += a[i][j];
}
if (sum % 2 != 0)
{
x = i;
num1++;
}
}
for ( i = 1; i <= n; i++)
{
int sum = 0;
for ( j = 1; j<= n;j++)
{
sum += a[j][i];
}
if (sum % 2 != 0)
{
y = i;
num2++;
}
} if (num1 == 0 && num2 == 0)
{
printf("OK\n");
}
else if (num1 == 1 && num2 == 1)
{
printf("Change bit (%d,%d)\n", x, y);
}
else
{
printf("Corrupt\n");
}
}
return 0;
}

POJ 2260 Error Correction 模拟 贪心 简单题的更多相关文章

  1. POJ 2260:Error Correction

    Error Correction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6014   Accepted: 3886 ...

  2. HDU 1753 大明A+B(字符串模拟,简单题)

    简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...

  3. hdu2187悼念512汶川大地震遇难同胞——老人是真饿了(贪心 简单题)

    传送门 简单题 #include<bits/stdc++.h> using namespace std; struct node { double dan,weight; }a[]; bo ...

  4. POJ 2393 贪心 简单题

    有一家生产酸奶的公司,连续n周,每周需要出货numi的单位,已经知道每一周生产单位酸奶的价格ci,并且,酸奶可以提前生产,但是存储费用是一周一单位s费用,问最少的花费. 对于要出货的酸奶,要不这一周生 ...

  5. 洛谷P5019 铺设道路 题解 模拟/贪心基础题

    题目链接:https://www.luogu.org/problemnew/show/P5019 这道题目是一道模拟题,但是它有一点贪心的思想. 我们假设当前最大的深度是 \(d\) ,那么我们需要把 ...

  6. cf 605A Sorting Railway Cars 贪心 简单题

    其实就是求总长度 - 一个最长“连续”自序列的长度 最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6... 遍历一遍,贪心就是了 遍历到第i个时,此时值为a[i], ...

  7. CF 500 C. New Year Book Reading 贪心 简单题

    New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n b ...

  8. HDU - 5999 The Third Cup is Free 贪心 简单题

    The Third Cup is Free Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  9. hectf2020部分简单题题解wp

    HECTF 我真是又菜又没时间肝题..又又又只水了波简单题... Reverse 1.Hello_Re file查一波 32bit,拖进IDA中 老规矩shift+F12 查看字符串: 跳转 F5查看 ...

随机推荐

  1. [hadoop]hadoop api 新版本与旧版本的差别

    突然现在对以后的职业方向有些迷茫,不知道去干什么,现在有一些语言基础,相对而言好的一些有Java和C,选来选去不知道该选择哪个方向,爬了好多网页后,觉得自己应该从java开始出发,之前有点心不在焉,不 ...

  2. 【BearChild】

    \(≧▽≦)/ BearChild is salty. If you want to save him,please call QQ:423339833 to talk♂with him. Have ...

  3. 写给“有钱大爷”、”美工殿下”、“前端文艺青年”的微信HTML5页面设计建议

    ==============================   2018更新 iphone X 的设计内容   ==============================     我保证你一分钟就 ...

  4. 最短路径之迪杰斯特拉(Dijkstra)算法

    对于网图来说,最短路径,是指两顶点之间经过的边上权值之和最少的路径,并且我们称路径上的第一个顶点为源点,最后一个顶点为终点.最短路径的算法主要有迪杰斯特拉(Dijkstra)算法和弗洛伊德(Floyd ...

  5. httpd功能配置之虚拟主机【转】

    apache默认使用80端口提供服务,使用主服务器配置的话,一台物理机只能提供一个站点服务:可以使用虚拟主机方式提供不同的访问,以实现一台主机提供多站点服务. 虚拟主机的实现方式有三种:基于端口.基于 ...

  6. Python爬取微信好友

    前言 今天看到一篇好玩的文章,可以实现微信的内容爬取和聊天机器人的制作,所以尝试着实现一遍,本文记录了实现过程和一些探索的内容 来源: 痴海 链接: https://mp.weixin.qq.com/ ...

  7. poj3636

    题意:每个物品有两个属性:长和宽(长宽不可互换).如果一个物品的长和宽均大于另一个物品,则这个物品可以罩住另一个物品,用这种罩住物品的方法将物品分组,一组之内的物品可以一个罩住一个的全部罩起来.问最少 ...

  8. scala tuple中的syntactic sugar

    List[Tuple2[String, Int]] // Base List[(String, Int)] // Syntactic sugar List[Tuple3[String, Float, ...

  9. python网络编程-socket上传下载文件(包括md5验证,大数据发送,粘包处理)

    ftp server 1) 读取文件名 2)检查文件是否存在 3)打开文件 4)检查文件大小 5)发送文件大小给客户端 6)等客户端确认 7)开始边读边(md5计算)发数据 8)给客户端发md5 ft ...

  10. JAVA复习笔记之GC部分

       前言:垃圾回收机制,大家都知道JAVA的垃圾回收都是JVM自动回收的,不需要程序员去管理.但是我们还是得知道原理才能在适当时机进行JVM调优 原理:当我们new 一个对象时JVM堆区就会分配一块 ...