问题 1003

题目描述

Alice and Bob are playing a game. Firstly, Bob writes several numbers on a chessboard, which is a n*m matrix. Then, it is Alice’s turn to operate. In Every operation, he is allowed to plus or minus a random number to the two adjoining squares. now, Alice wants to know whether there is an operation which can change all the number of the chessboard into zeros.

输入

The first line contains an integer T(1 <= T <= 10), indicating the number of test cases.For each test case there is a line,contains two integer n,m(1<=n,m<=500), and next n lines,each line contain m integers,indicating the matrix.

输出

For each test case,if Alice can change all the number of the chessboard into zeros, then print "Yes", or print "No"

样例输入

2 1 1 1 2 2 3 4 6 7

样例输出

No Yes
 
 
开始一直不对,后面发现因为数据溢出了……伤感……
 
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
     int  a;
     scanf( "%d", &a );
     while( a-- )
     {
         int n, m, f[1000][1000];
          scanf( "%d%d", &n, &m );
          int i, j, t, sum[1000];
          for( i = 0; i < n; i++ )
             for( j = 0; j < m; j++ )
                scanf( "%d", &f[i][j] );
         for( i = 0; i < n; i++ )
             for( j = 0; j < m - 1; j++ )
                  f[i][j++] -= f[i][j];
          for( i = 0; i < n - 1; i++ )
               f[i++][j] -= f[i][j];
          if( f[i++][j] == 0 )
             printf( "Yes\n" );
          else
             printf( "No\n" );
      }
}
原文地址:https://www.cnblogs.com/zsj576637357/p/2284218.html