N*M bulbs

 Accepts: 94
 Submissions: 717
 Time Limit: 10000/5000 MS (Java/Others)
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
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
刚好除了第一盏灯,其他灯都只经过偶数次。

思路:

看见题大致乱想了一下,感觉001 和 0001这种最后都能变成100和1000这种,而且人在1这个点,于是看成无论是相隔奇数个还是偶数个0都能转移到起点。最后就成了判断起点0,1,然后判断能否到达终点。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 10000;
int a[maxn][maxn]; int main()
{
int T;
int n,m;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
int num = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
{
scanf("%d",&a[i][j]);
if(a[i][j] == 1)
num++;
}
if(num % 2)
{
if((n + m) % 2)
printf("NO\n");
else
printf("YES\n");
}
else
{
if((n + m) % 2 == 0)
printf("NO\n");
else
printf("YES\n");
}
}
return 0;
}

  

hdu5601 BestCoder Round #67 (div.2)的更多相关文章

  1. BestCoder Round #67 (div.2) N bulbs(hdu 5600)

    N bulbs Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

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

    问题描述 N*M个灯泡排成一片,也就是排成一个N*M的矩形,有些开着,有些关着,为了节约用电,你要关上所有灯,但是你又很懒. 刚好有个熊孩纸路过,他刚好要从左上角的灯泡走去右下角的灯泡,然后离开. 但 ...

  3. hdu 5600 BestCoder Round #67 (div.2)

    N bulbs  Accepts: 275  Submissions: 1237  Time Limit: 10000/5000 MS (Java/Others)  Memory Limit: 655 ...

  4. 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 ( ...

  5. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  6. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  7. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

  8. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  9. hdu5634 BestCoder Round #73 (div.1)

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. Linux 磁盘和文件管理系统 文件打包解压备份 VIM、VI编辑器

  2. cord-in-a-box 2.0 安装指南

    [TOC] 这篇文章简要介绍了 Ciab2.0 的安装. 包括硬件, 软件环境的选择, Ciab2.0的实际部署架构, 安装过程等. 下面就先对 Ciab2.0 部署环境做简要介绍. 1. 概述 这一 ...

  3. 构建自己的 PHP 框架

    这是一个系列的文章,项目地址在这里,欢迎大家star. 这个框架前一部分比较像Yii,后一部分比较像Laravel,因为当时正在看相应框架的源码,所以会有不少借鉴参考.捂脸- 这个框架千万不要直接应用 ...

  4. js判断操作系统windows,ios,android(笔记)

    使用JS判断用户使用的系统是利用浏览器的userAgent. navigator.userAgent:userAgent 获取了浏览器用于 HTTP 请求的用户代理头的值. navigator.pla ...

  5. css3兼容IE8的方案 各个ie的hack

    虽然现在很多项目已经对低版本IE不要求了,但是还有部分公司对IE8还是很执着的,咱作为屌丝前端程序员不能和老板说前端潮流,不能说趋势,只能动脑子了,下面就分享一些css3兼容ie8的方案思路.主要是实 ...

  6. 算法题丨Move Zeroes

    描述 Given an array nums, write a function to move all 0's to the end of it while maintaining the rela ...

  7. angular2 学习笔记 ( Rxjs, Promise, Async/Await 的区别 )

    Promise 是 ES 6 Async/Await 是 ES 7 Rxjs 是一个 js 库 在使用 angular 时,你会经常看见这 3 个东西. 它们都和异步编程有关,有些情况下你会觉得用它们 ...

  8. OAuth2.0学习(1-2)OAuth2.0的一个企业级应用场景 - 新浪开放平台微博OAuth2.0认证

    http://open.weibo.com/wiki/%E9%A6%96%E9%A1%B5 开发者可以先浏览OAuth2.0的接口文档,熟悉OAuth2.0的接口及参数的含义,然后我们根据应用场景各自 ...

  9. C# 文件的一些基本操作

    近期程序中经常用到一些文件的操作,现在大致整理一下. 一. 获取文件或文件夹基本信息 1.获取文件信息,组成一个DataTable信息. /// <summary> /// 获取指定目录下 ...

  10. java循环遍历类属性 get 和set值方法

    //遍历sqspb类 成员为String类型 属性为空的全部替换为"/"Field[] fields = sqspb.getClass().getDeclaredFields(); ...