POJ 2260 Error Correction 模拟 贪心 简单题
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6825 | Accepted: 4289 |
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
than 0 and 1 will occur in the matrix. Input will be terminated by a value of 0 for n.
Output
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 模拟 贪心 简单题的更多相关文章
- POJ 2260:Error Correction
Error Correction Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6014 Accepted: 3886 ...
- HDU 1753 大明A+B(字符串模拟,简单题)
简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...
- hdu2187悼念512汶川大地震遇难同胞——老人是真饿了(贪心 简单题)
传送门 简单题 #include<bits/stdc++.h> using namespace std; struct node { double dan,weight; }a[]; bo ...
- POJ 2393 贪心 简单题
有一家生产酸奶的公司,连续n周,每周需要出货numi的单位,已经知道每一周生产单位酸奶的价格ci,并且,酸奶可以提前生产,但是存储费用是一周一单位s费用,问最少的花费. 对于要出货的酸奶,要不这一周生 ...
- 洛谷P5019 铺设道路 题解 模拟/贪心基础题
题目链接:https://www.luogu.org/problemnew/show/P5019 这道题目是一道模拟题,但是它有一点贪心的思想. 我们假设当前最大的深度是 \(d\) ,那么我们需要把 ...
- cf 605A Sorting Railway Cars 贪心 简单题
其实就是求总长度 - 一个最长“连续”自序列的长度 最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6... 遍历一遍,贪心就是了 遍历到第i个时,此时值为a[i], ...
- 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 ...
- 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 ...
- hectf2020部分简单题题解wp
HECTF 我真是又菜又没时间肝题..又又又只水了波简单题... Reverse 1.Hello_Re file查一波 32bit,拖进IDA中 老规矩shift+F12 查看字符串: 跳转 F5查看 ...
随机推荐
- 活学活用,CSS清除浮动的4种方法
清除浮动这个问题,做前端的应该再熟悉不过了,咱是个新人,所以还是记个笔记,做个积累,努力学习向大神靠近. CSS清除浮动的方法网上一搜,大概有N多种,用过几种,说下个人感受. 1.结尾处加空div标签 ...
- supervisor简洁用例
supervisor是什么 superviosr是一个Linux/Unix系统上进程监控和管理的工具,它由python编写,可以用pip安装.supervisor能将一个普通的命令行进程变为后台dae ...
- 44、File类简介
使用File类创建文件夹 File类在java.io包下,看名字应该可以猜到,这个类是跟文件夹操作有关,下面使用File类中的方法在硬盘中创建文件夹. package com.sutaoyu.file ...
- 公司xenserver搭建的使用
[root@xenserver ~]# ls -l /dev/disk/by-path/total 0lrwxrwxrwx 1 root root 9 Jan 19 16:33 pci-0000:0 ...
- 【前端】h5音乐播放demo 可关闭可播放
复制如下代码,直接可预览(记得把超链接换成自己本地路径) <!DOCTYPE html> <html> <head> <meta charset=" ...
- 移动端默认meta标签
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><met ...
- java基础60 JavaScript字符串转换成数字(网页知识)
1.字符串转换成数字 <!doctype html> <html> <head> <meta charset="utf-8"> &l ...
- JAVA随笔(三)
私有是针对类的,而不是对象. static 函数,其实是类函数.之前一直不太理解每个类中的static main是什么意思,为什么main中不能直接调用非静态的变量:因为main是 类函数,不是属于某 ...
- malloc和free的实现
C++ Code 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...
- sqlserver中的全局变量总结
@@CONNECTIONS返回自上次启动 Microsoft? SQL Server? 以来连接或试图连接的次数.@@CPU_BUSY返回自上次启动 Microsoft? SQL Server? 以来 ...