UVa 541 - Error Correction
来源:互联网 发布:查莉娅数据伤害 编辑:程序博客网 时间:2024/05/04 02:49
题目:在一个n x n的0和1组成的矩阵,问是否每行每列之和为偶数,如果不是是否通过改变一个元素值后成立。
分析:简单题。直接统计所有的行和列的偶数情况:
1.都是偶数则成立;
2.如果有1行和1列是奇数则改变交点的值即可;
3.其他情况,均为不可能转换。
注意:数组开大一点。
#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;int mat[105][105];int main(){int n;while ( ~scanf("%d",&n) && n ) {for ( int i = 0 ; i < n ; ++ i )for ( int j = 0 ; j < n ; ++ j )scanf("%d",&mat[i][j]);int c_count = 0,c_save;int r_count = 0,r_save;for ( int i = 0 ; i < n ; ++ i ) {int count_c = 0,count_r = 0;for ( int j = 0 ; j < n ; ++ j ) {if ( mat[i][j]%2 ) count_c ++;if ( mat[j][i]%2 ) count_r ++;}if ( count_c%2 ) {c_count ++;c_save = i;}if ( count_r%2 ) {r_count ++;r_save = i;}}if ( r_count == 0 && c_count == 0 )printf("OK\n");else if ( r_count == 1 && c_count == 1 )printf("Change bit (%d,%d)\n",c_save+1,r_save+1);else printf("Corrupt\n");}return 0;}
- UVa 541 - Error Correction
- UVa 541Error Correction
- UVA 541 Error Correction【水题】
- Error Correction
- Error Correction
- Error Correction
- Error Correction
- Error Correction
- fjnu 1142 Error Correction
- zoj 1949 Error Correction
- zoj 1949 Error Correction
- ZOJ 1949Error Correction
- zoj 1949 Error Correction
- zoj1949-------------Error Correction
- ZOJ 1949 Error Correction
- zoj 1949.Error Correction
- zoj 1949 Error Correction
- ZOJ 1949 Error Correction
- SSH整合包详解.Struts2.2.3+Spring3.1.0.M2+Hibernate3.6.6
- 进制转换
- C语言编程——数组排序
- OpenCV(二)如何对图像的像素进行操作
- Leetcode: Linked List Cycle II
- UVa 541 - Error Correction
- VirtualBox 更新后,COM组件注册失败问题
- JDBC批量插入、批量删除、批量更新
- 事件驱动I/O模型
- Oracle 存储过程 无法编译 解决方法
- VC 获取鼠标当前位置坐标和RGB
- UVA 706 - LCD Display(液晶显示器)
- Hadoop RPC概述
- C#常用方法总结