HDU 5601 N*M bulbs

N*M bulbs

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 434    Accepted Submission(s): 253


Problem Description
N*M bulbs are in a rectangle, some are on, and some are off.

in order to save electricity, you should turn off all the lights, but you're lazy.
coincidentally,a passing bear children paper(bear children paper means the naughty boy), who want to pass here from the top left light bulb to the bottom right one and leave.

he starts from the top left light and just can get to the adjacent one in one step.
But after all,the bear children paper is just a bear children paper. after leaving a light bulb to the next one, he must touch the switch, which will change the status of the light.

your task is answer whether it's possible or not to finishing turning off all the lights, and make bear children paper also reach the bottom right light bulb and then leave at the same time.
 

Input
The first line of the input file contains an integer T, which indicates the number of test cases.

For each test case, there are n+1 lines.

The first line of each test case contains 2 integers n,m.

In the following n line contains a 01 square, 0 means off and 1 means on.

* T10
* N,M1000
 

Output
There should be exactly T lines in the output file.

The i-th line should only contain "YES" or "NO" to answer if it's possible to finish.
 

Sample Input
   
   
   
   
1 1 5 1 0 0 0 0
 

Sample Output
   
   
   
   
YES
Hint
Child's path is: (1,1)(1,2)(1,3)(1,2)(1,3)(1,4)(1,5)(4,5) all switches are touched twice except the first one.
 

Source
BestCoder Round #67 (div.2)
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5674  5673  5672  5671  5669 
 这个题需要注意的地方是当有偶数行时http://blog.csdn.net/z8110/article/details/50523291
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int t,i,j,k,l,m,n,num1,num2;
	scanf("%d",&t);
	while(t--)
	{
		num1=0;
		num2=0;
		scanf("%d%d",&m,&n);
		for(i=0;i<m-1;i++)
		for(j=0;j<n;j++)
		{
			scanf("%d",&k);
			if(k==0)
			num1++;
		}
		for(j=0;j<n;j++)
		{
			scanf("%d",&l);
			if(l==0)
			num2++;
		}
		if(m%2&&(num1+num2)%2==0)
		printf("YES\n");
		else if(m%2==0&&num1%2==0&&(n-num2)%2)
		printf("YES\n");
		else if(m%2==0&&num1%2&&(n-num2)%2==0)
		printf("YES\n");
		else
		printf("NO\n");
	}
	return 0;
}


你可能感兴趣的:(HDU 5601 N*M bulbs)