hdu5601N*M bulbs
2015-12-28 01:12
288 查看
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5601
题意:给你一个n*m的矩阵,矩阵内每一个位置的值是0或1,给定的是初始状态,然后让你从左上角走到右下角,每次都能向着4个方向走,每走到一个格子的时候它原来的值x^=1。问最后是否能从右下角离开时使得整个矩阵全部为0。
分析:其实出题人在解释了题目样例之后还是挺好想的,首先我们能知道想将原来的1变为0的话我们只能通过奇数次,原来为0的话我们通过的次数要为偶数次,这样说好像把题目变麻烦了,但是!如果我们拿着笔在矩阵中画的话很容易就能看出最多同时有两个连在一起的格子会有影响,我们可以想象成是一条长度永远为2的贪吃蛇在地图上走来走去,先把全部的1都"吃"掉,最后走00这种地形,也就是出题人解释样例的那种折叠走,很简单我们的目的点在map
[m],那么我们在走到map
[m]旁边怎么样就能刚好使得所有都为0的时候同时还在(n,m)上呢?很容易想到这和n+m的奇偶性是有关系的,至于哪种是YES哪种是NO就自己随便写两组数据就能分辨出来了。
代码:
#include<map> #include<set> #include<cmath> #include<queue> #include<math.h> #include<cstdio> #include<vector> #include<string> #include<cstring> #include<iostream> #include<algorithm> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int N=1010; const int MAX=151; const int MOD=1000007; const int MOD1=100000007; const int MOD2=100000009; const int INF=1000000000; const double EPS=0.00000001; typedef long long ll; typedef unsigned long long ull; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int a ; int main() { int i,j,t,n,m,bo,tot; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); bo=tot=0; for (i=1;i<=n;i++) for (j=1;j<=m;j++) { scanf("%d", &a[i][j]);tot+=a[i][j]; } if ((tot&1)&&!((n+m)&1)) bo=1; if (!(tot&1)&&((n+m)&1)) bo=1; if (bo) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- 终极选择---老男孩教育
- destoon代码从头到尾捋一遍
- iOS开发多线程篇—GCD介绍
- React 学习二 组件
- webBrowser捕获Alert内容(C#)
- 二分 51Nod1105 第K大的数
- JDK中的Timer和TimerTask详解
- BigDecimal,DecimalFormat,BigInteger和SimpleDateFormat
- ShellExecuteEx(&ShExecInfo) 和 WinExec
- Swift中避免重载的final修饰符
- unity, StopAllCoroutines导致bug的解决办法
- 列表中循环添加字典出现覆盖现象的问题
- 初涉驱动实验
- 深入浅出JVM
- 总结报告
- [android]_[四种基本布局]
- 彩色文字 逐字显示 ,三年前写的了,现在看不懂了,悲催,因为BAT语言比较低级(底层)....
- 黑马程序员——反射的使用
- [LeetCode] 56. Merge Intervals 解题思路
- Android开发之应用程序创建与目录结构