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. 1 0 1 0

  2. 0 0 0 0

  3. 1 1 1 1

  4. 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

  1. 4
  2. 1 0 1 0
  3. 0 0 0 0
  4. 1 1 1 1
  5. 0 1 0 1
  6. 4
  7. 1 0 1 0
  8. 0 0 1 0
  9. 1 1 1 1
  10. 0 1 0 1
  11. 4
  12. 1 0 1 0
  13. 0 1 1 0
  14. 1 1 1 1
  15. 0 1 0 1
  16. 0

Sample Output

  1. OK
  2. Change bit (2,3)
  3. Corrupt

计算每行每列1的数量,看奇数个的交叉点,大于一个或没有则不能实现。

  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int a[105][105];
  6. int n;
  7. while (~scanf("%d", &n))
  8. {
  9. int i, j;
  10. int num1 = 0,num2=0;
  11. if (!n)
  12. {
  13. break;
  14. }
  15. int x, y;
  16. for ( i = 1; i <= n; i++)
  17. {
  18. int sum = 0;
  19. for ( j = 1; j <= n; j++)
  20. {
  21. scanf("%d", &a[i][j]);
  22. sum += a[i][j];
  23. }
  24. if (sum % 2 != 0)
  25. {
  26. x = i;
  27. num1++;
  28. }
  29. }
  30. for ( i = 1; i <= n; i++)
  31. {
  32. int sum = 0;
  33. for ( j = 1; j<= n;j++)
  34. {
  35. sum += a[j][i];
  36. }
  37. if (sum % 2 != 0)
  38. {
  39. y = i;
  40. num2++;
  41. }
  42. }
  43.  
  44. if (num1 == 0 && num2 == 0)
  45. {
  46. printf("OK\n");
  47. }
  48. else if (num1 == 1 && num2 == 1)
  49. {
  50. printf("Change bit (%d,%d)\n", x, y);
  51. }
  52. else
  53. {
  54. printf("Corrupt\n");
  55. }
  56. }
  57. return 0;
  58. }

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. linux nginx大量TIME_WAIT的解决办法--转

    netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' TIME_WAIT 8535 CLOSE_WAIT 5 FIN ...

  2. Sort Colors I & II

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  3. unity 优秀开源项目

    ihaiu.GUIDRef (查看项目资源使用情况) http://blog.ihaiu.com/unity-GUIDRef Ihaiu.PoolManager (对象池) http://github ...

  4. Android性能测试工具之APT

    1.APT工具简介: APT是一个eclipse插件,可以实时监控Android手机上多个应用的CPU.内存数据曲线,并保存数据:另外还支持自动获取内存快照.PMAP文件分析等,方便开发人员自测或者测 ...

  5. tftp的安装

    下载并且安装软件xinetd tftp tftpd sudo apt-get install xinetd tftp tftpd 在/etc/xinetd.d/下建立一个配置文件tftp sudo v ...

  6. 洛谷P1455搭配购买

    传送门啦 这是强连通分量与背包的例题 需要注意的就是价值和价格两个数组不要打反了.. 另外 这是双向图!!! #include <iostream> #include <cstdio ...

  7. (二)SpringMVC控制器

    第一节:@RequestMapping请求映射 第二节:@RequestParam请求参数 第三节:ModelAndView返回模型和视图 第四节:SpringMVC对象属性自动封装 第五节:Spri ...

  8. SQL SERVER 断开所有连接(转)

    通过sql server management studio对数据进行管理,比如数据库改名等,经常遇到有正在运行的连接,以致无法操作,这时候断掉所有的连接很有必要.代码如下:(会断掉某个库的所有连接, ...

  9. Django数据库数据表操作

    建立表单 django通过设置类来快速建表,打开models.py 例: from __future__ import unicode_literals from django.db import m ...

  10. 适合新手的web开发环境

    学习web开发,环境搭建是必不可少的一个环节.你可以使用wamp一键安装包,或者使用sae.bae.gae这种PaaS平台来部署,或者安装*nix系统在本地部署. 对于一个希望体验LAMP式建站的新手 ...