HRBUST 2219 Recover the Matrix(水题)

来源:互联网 发布:辣鸡软件表情 编辑:程序博客网 时间:2024/06/08 05:32

Time Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 2(2 users)Total Accepted: 1(1 users)Rating: Special Judge: NoDescriptionGiven two n * m matrix a containing only 1 and 0. Bob will generate a new n * m matrix b. Each element b[i][j] in matrix b is the OR operation result of every elements in the same row or same column with b[i][j]. (b[i][j] = a[0][j] | a[1][j] | ... | a[n][j] | a[i][0] | a[i][1] | ... | a[i][m]).
Bob sometimes makes mistakes. So we will give you matrix b and let you determine whether Bob has made a mistake. If not, you need to output if there is a possible original matrix.
InputFirst line of input contains only integer T, indicating the number of test cases.
First line of each test case contains two integer n and m (the numbers of rows and columns of the matrix won't exceed 100).
Then n lines follows, each line contains m numbers describing the matrix. Each numbers can only be 1 or 0.
OutputFor each test case, if Bob made no mistake, output "YES". Output "NO" if he did.Sample Input2
2 2
1 0
0 0
2 3
1 1 1
1 1 1
Sample OutputNO
YES
#include<stdio.h>#include<string.h>using namespace std;int a[1003][1003];int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n,m;        scanf("%d%d",&n,&m);        for(int i=0;i<n;i++)        {            for(int j=0;j<m;j++)            {                scanf("%d",&a[i][j]);            }        }        int f=0;        for(int j=0;j<m;j++)        {            int tem=a[0][j];            for(int i=1;i<n;i++)            {                if(a[i][j]!=tem)                    f=1;            }        }        if(f)            printf("NO\n");        else printf("YES\n");    }}



0 0
原创粉丝点击