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查看 ...
随机推荐
- Sparse Filtering简介
当前很多的特征学习(feature learning)算法需要很多的超参数(hyper-parameter)调节, Sparse Filtering则只需要一个超参数--需要学习的特征的个数, 所以非 ...
- angular4 get,post请求(带参数,与不带参数)
一:在app.module.ts引入HttpMoudle import { BrowserModule } from '@angular/platform-browser'; import { Htt ...
- 边框画的三角形给shadow
本文地址:http://www.cnblogs.com/veinyin/p/8690882.html 要写一个对话气泡样式,我们首先想到的当然给是一个盒子,然后用边框画一个三角形定位过去. 如果不需 ...
- 基本控件文档-UISwitch属性
CHENYILONG Blog 基本控件文档-UISwitch属性 Fullscreen UISwitch属性 技术博客http://www.cnblogs.com/ChenYilong/ 新 ...
- c++刷题(15/100)矩阵转置,最深子树
题目一:矩阵转置 给定一个矩阵 A, 返回 A 的转置矩阵. 矩阵的转置是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引. 示例 1: 输入:[[1,2,3],[4,5,6],[7,8,9]] 输出 ...
- 50、多线程创建的三种方式之实现Runnable接口
实现Runnable接口创建线程 使用Runnable创建线程步骤: package com.sutaoyu.Thread; //1.自定义一个类实现java.lang包下的Runnable接口 cl ...
- Linux基础操作命令-打包压缩
将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) 将用户信息数据库文件和用户密码数据库文件纵向合并为一个文件/2.txt(追加) 将/1.txt./2.txt两个文件打包为 ...
- 网络流最大流(拆点)(附带kuangbin最大流模板)(目测这个题有bug)
题目链接:https://vjudge.net/contest/68128#problem/H 我觉得这个题有bug,如果饮料和食物都为0,但是同时有五个人什么也不需要,按道理来讲,最多受益的人数为5 ...
- 20165230 《Java程序设计》实验四 Android程序设计实验报告
20165230 <Java程序设计>实验四 Android程序设计实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:田坤烨 学号:20165230 成绩: 指导 ...
- jQuery遍历方式
对象遍历