ACM-DataStructure-Day3 Error Correction
来源:互联网 发布:五级三晋制工资算法 编辑:程序博客网 时间:2024/06/03 21:57
题意:
给出布尔矩阵的大小,并给出矩阵,让你判断是否每行每列之和都是even sum(偶数),
如果是偶数则输出OK,
如果不是偶数,若能够只改某一点的值使得该矩阵满足题意,则输出Change bit (a,b);
如果以上都不满足,则输出 Corrupt;
难点分析:
经过分析可以知道,若需要修改某一点的值的话,那么该点所在的行,所在的列的sum都会发生改变。
所以思路就是:分别对每一行每一列求和,经过判断只有1行1列的和不是偶数的话则需要修改该点的值;剩下的情况就很简单了。
给出AC代码:
#include <iostream>#include <stdio.h>#include <cstring>using namespace std;const int N=100;bool matrix[N][5];int check[N][3];int sum=0,n;void Input(){int i,j;sum=0;memset(check,0,sizeof(check));for(i=1;i<=n;i++){ for(j=1;j<=n;j++) { cin>>matrix[i][j]; check[i][1]+=matrix[i][j]; sum+=matrix[i][j]; }}for(j=1;j<=n;j++){ for(i=1;i<=n;i++) check[j][2]+=matrix[i][j];}}int main(){ while(cin>>n&&n!=0){ Input();int i,flag1,flag2,Count1=0,Count2=0; for(i=1;i<=n;i++){ if(check[i][2]%2) {Count2++;flag2=i;}//cout<<"the lie error is :"<<i<<endl; if(check[i][1]%2) {Count1++;flag1=i;}//cout<<"the hang error is :"<<i<<endl; } if(Count1==1&&Count2==1) printf("change bit (%d,%d)\n",flag1,flag2); else if(Count1==0&&Count2==0) printf("OK\n"); else printf("Corrupt\n"); } return 0;}总结:这个涉及到线性关系吗????我也不知道
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
#include <stdio.h>
#include <cstring>
using namespace std;
const int N=100;
bool matrix[N][5];
int check[N][3];
int sum=0,n;
bool matrix[N][5];
int check[N][3];
int sum=0,n;
void Input(){
int i,j;sum=0;
memset(check,0,sizeof(check));
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cin>>matrix[i][j];
check[i][1]+=matrix[i][j];
sum+=matrix[i][j];
}
}
for(j=1;j<=n;j++)
{
for(i=1;i<=n;i++)
check[j][2]+=matrix[i][j];
}
}
int main()
{
while(cin>>n&&n!=0){
Input();int i,flag1,flag2,Count1=0,Count2=0;
/*if(sum>9||sum<7) cout<<"Corrupt"<<endl;
else{*/
for(i=1;i<=n;i++){
if(check[i][2]%2) {Count2++;flag2=i;}//cout<<"the lie error is :"<<i<<endl;
if(check[i][1]%2) {Count1++;flag1=i;}//cout<<"the hang error is :"<<i<<endl;
int i,j;sum=0;
memset(check,0,sizeof(check));
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cin>>matrix[i][j];
check[i][1]+=matrix[i][j];
sum+=matrix[i][j];
}
}
for(j=1;j<=n;j++)
{
for(i=1;i<=n;i++)
check[j][2]+=matrix[i][j];
}
}
int main()
{
while(cin>>n&&n!=0){
Input();int i,flag1,flag2,Count1=0,Count2=0;
/*if(sum>9||sum<7) cout<<"Corrupt"<<endl;
else{*/
for(i=1;i<=n;i++){
if(check[i][2]%2) {Count2++;flag2=i;}//cout<<"the lie error is :"<<i<<endl;
if(check[i][1]%2) {Count1++;flag1=i;}//cout<<"the hang error is :"<<i<<endl;
}
/*if(check[1][1]!=2) {Count1++;flag1=1;cout<<"the hang error is :"<<flag1<<endl;}
if(check[2][1]!=0) {Count1++;flag1=2;cout<<"the hang error is :"<<flag1<<endl;}
if(check[3][1]!=4) {Count1++;flag1=3;cout<<"the hang error is :"<<flag1<<endl;}
if(check[4][1]!=2) {Count1++;flag1=4;cout<<"the hang error is :"<<flag1<<endl;}*/
/*if(check[1][1]!=2) {Count1++;flag1=1;cout<<"the hang error is :"<<flag1<<endl;}
if(check[2][1]!=0) {Count1++;flag1=2;cout<<"the hang error is :"<<flag1<<endl;}
if(check[3][1]!=4) {Count1++;flag1=3;cout<<"the hang error is :"<<flag1<<endl;}
if(check[4][1]!=2) {Count1++;flag1=4;cout<<"the hang error is :"<<flag1<<endl;}*/
if(Count1==1&&Count2==1)
printf("change bit (%d,%d)\n",flag1,flag2);
else if(Count1==0&&Count2==0)
printf("OK\n");
else
printf("Corrupt\n");
}
return 0;
}
printf("change bit (%d,%d)\n",flag1,flag2);
else if(Count1==0&&Count2==0)
printf("OK\n");
else
printf("Corrupt\n");
}
return 0;
}
阅读全文
0 0
- ACM-DataStructure-Day3 Error Correction
- ACM-DataStructure-Day3——A
- 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
- POJ2260:Error Correction
- Codeforces828 D. High Load
- 三栏布局——左右固定,中间自适应
- algorithm库介绍之---- stable_sort()方法 与 sort()方法
- vue-router 导航钩子
- centos7 Firewall的配置
- ACM-DataStructure-Day3 Error Correction
- phpMyAdmin
- 数据抽取方式和各方式特点
- spring中异步配置
- Z字形编排
- rxjava+Retrofit+okhttp 实战网络请求
- 初始化容器
- [LeetCode]127. Word Ladder 深入浅出讲解和代码示例
- 记:第一次使用Nginx搭建图片服务器