BestCoder Round #67 (div.2) N*M bulbs

问题描述

N*M个灯泡排成一片,也就是排成一个N*M的矩形,有些开着,有些关着,为了节约用电,你要关上所有灯,但是你又很懒。
刚好有个熊孩纸路过,他刚好要从左上角的灯泡走去右下角的灯泡,然后离开。
但是毕竟熊孩纸,熊孩纸在离开一个灯泡之前,一定会动一下当前开关,也就是开的变关,关的变开。
想问你可不可能关完所有的灯,同时熊孩纸也可以到达右下角的灯泡,然后离开。

输入描述

第一行T,表示T组数据。
接下来T组数据:
每组数据,第一行N,M,后面一个N*M的01矩阵,表示灯泡的初始开关状态,0表示关,1表示开。

1 \leq T \leq 101≤T≤10
1 \leq N, M \leq 10001≤N,M≤1000

输出描述

每组数据,如果可以输出"YES",否则输出"NO"。

输入样例

1
1 5
1 0 0 0 0

输出样例

YES

Hint

孩子的路径是:123234545
刚好除了第一盏灯,其他灯都只经过偶数次。

总的操作次数是跟nn奇偶的。如果1的总数和n的奇偶性不同,就是无解,如果奇偶性相同,有解。

 1 #include <iostream>
 2 #include <cstdio>
 3 int t,n,count,a;
 4 int main(int argc, char** argv)
 5 {
 6     scanf("%d",&t);
 7     while(t--)
 8     {
 9         scanf("%d",&n);
10         count=0;
11         for(int i=0;i<n;i++)
12         {
13             scanf("%d",&a);
14             if(a==1) count++;
15         }
16         if(count%2==0&&n%2==0||count%2!=0&&n%2!=0)
17             printf("Yes\n");
18         else
19             printf("No\n");
20     }
21     return 0;
22 }
时间: 2024-08-05 08:36:33

BestCoder Round #67 (div.2) N*M bulbs的相关文章

计算几何(水)BestCoder Round #50 (div.2) 1002 Run

题目传送门 1 /* 2 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 3 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-8 19:54:14 8 * File Name :B.cpp 9 ************

hdu5418 BestCoder Round #52 (div.2) Victor and World ( floyd+状压dp)

Problem Description After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fly around the world. There are n countries on the earth, which are numbered from 1 to

BestCoder Round #11 (Div. 2) 前三题题解

题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 216    Accepted Submission(s): 166 Problem De

BestCoder Round #11 (Div. 2) 题解

HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 302    Accepted Submission(s): 229 Problem Description Bob and Alice got separated in the Square, they agreed that if they

HDU 5651 xiaoxin juju needs help(BestCoder Round #77 (div.1)1001)

传送门 xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 861    Accepted Submission(s): 243 Problem Description As we all known, xiaoxin is a brilliant coder. He knew **palin

BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 681    Accepted Submission(s): 280 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the

BestCoder Round #50 (div.2)

题目传送:BestCoder Round #50 (div.2) BC感觉越做越无语了 1001.Distribution money AC代码: #include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <queue> #include <stack> #include <bitset> #

HDU 5671 Matrix (BestCoder Round #81 (div.2) 1002)

传送门 Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 311    Accepted Submission(s): 142 Problem Description There is a matrix M that has n rows and m columns (1≤n≤1000,1≤m≤1000).Then we

DP BestCoder Round #50 (div.2) 1003 The mook jong

题目传送门 1 /* 2 DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: 3 dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp[i][0] = dp[i-1][1] + dp[i-1][0]; 4 比赛时二维dp写搓了,主要是边界情况的判断出错,比如dp[3][1] = 1,因为第3块放了木桩,其他地方不能再放,dp[3][0]同理 5 解释一下dp[i][1]的三种情况,可能是前面相隔2个放的方案或者是不放的