【51nod】1851 俄罗斯方块
题解
最近一遇到神仙题一卡就好久……做点水题滋养一下自己吧= =
显然我们发现放一个方块的奇偶性不会改变,所以格子如果黑格子是奇数,那么就是No
我们发现每个2 × 3的方格里的2 × 1的黑格子都可创造并且平移,这样我们就可以愉快地造出4的倍数了,所以这种情况只要判黑格子奇偶性就行
那么2×2的特判是不是全白或全黑
1×?的从后往前扫,扫到一个黑格子用1*4填一下,不能填证明是No
代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 1000005
//#define ivorysi
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 - '0' + c;
c = getchar();
}
res = res * f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
int T,N,M;
int a[10000005],cnt,d[10000005];
int c(int i,int j) {
return (i - 1) * M + j;
}
void Solve() {
read(N);read(M);
cnt = 0;
for(int i = 1 ; i <= N ; ++i) {
char ch = getchar();
while(ch != '1' && ch != '0') ch = getchar();
for(int j = 1 ; j <= M ; ++j) {
a[c(i,j)] = ch - '0';
d[c(i,j)] = 0;
if(a[c(i,j)] == 1) ++cnt;
ch = getchar();
}
}
if(!cnt) {puts("Yes");return;}
if(N == 1 || M == 1) {
if(cnt & 1) {puts("No");return;}
for(int i = 1 ; i <= max(N,M) ; ++i) {
d[i] ^= d[i - 1];
if((a[i] ^ d[i]) == 1) {
if(i + 3 > max(N,M)) {puts("No");return;}
d[i] ^= 1;d[i + 4] ^= 1;
}
}
puts("Yes");
}
else {
if(max(N,M) >= 3) {
if(cnt & 1) puts("No");
else puts("Yes");
}
else {
if(cnt == 4 || cnt == 0) puts("Yes");
else puts("No");
}
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
read(T);
while(T--) {
Solve();
}
}
【51nod】1851 俄罗斯方块的更多相关文章
- 51nod 1851俄罗斯方块(trick)
题目大意:给出一个黑白图,你可以选定一个俄罗斯方块的区域,黑白翻转,问能否变成白图 比较trick的题目, 首先可以想到,奇数个1肯定是无解的,所以考虑偶数个1 可以先讨论n是2的情况 当n为2时,其 ...
- 51nod 1851 俄罗斯方块
玩过俄罗斯方块?那你知道俄罗斯方块共有七种吧(其实只有五种) 给一个黑白图,每次能将某些区域的格子黑白反转,至于某些区域的意思嘛,就是俄罗斯方块形状的区域咯(可水平翻转.上下翻转.旋转) 求能否将图变 ...
- 还是俄罗斯方块之android版
前面的,口水话 请直接跳过. 虽然现在不比以前了 也没多少人气了,放到首页 都不到几百的点击量.也许博客园整体水平也是在往水的方向发展.不谈那些了,哥也曾经辉煌过 有过一天上千的点击量 ,哥也曾经有过 ...
- x01.Tetris: 俄罗斯方块
最强大脑有个小孩玩俄罗斯方块游戏神乎其技,那么,就写一个吧,玩玩而已. 由于逻辑简单,又作了一些简化,所以代码并不多. using System; using System.Collections.G ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- 51Nod 1428 活动安排问题
51Nod 1428 活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
- 俄罗斯方块C#版
using System; using System.Windows.Forms; using System.Drawing; using System.Media; class me : Form ...
随机推荐
- Docker 基础知识
Docker Docker 是什么 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是 ...
- 求助大佬3——hash姿势
某同学的hash姿势: 完整代码:http://www.cnblogs.com/TheRoadToTheGold/p/6370487.html long long get_hash1(long lon ...
- 已经菜到不行了 PAT 1010. Radix (25)
https://www.patest.cn/contests/pat-a-practise/1010 题目大意: 输入四个数字,a,b,c,d. a和b是两个数字,c=1表示是第一个数字,c=2表示是 ...
- CF869 C 组合
先吐槽下,题面套的物语系列欸.. 由于距离为3,那么必定两种颜色间要填入第3种颜色,否则就是单独点的情况,那么两两之间可以单独考虑而不影响答案,枚举两种颜色之间边数,计算一边的组合和另一边的排列,最后 ...
- jenkins 相关默认信息
(1) 默认安装目录 /usr/lib/jenkins/:jenkins安装目录,WAR包会放在这里. ( 2 ) 默认配置文件 /etc/sysconfig/jenkins:jenkins ...
- 为了拿Ph.D而做出的诺贝尔奖
- Java并发编程原理与实战十九:AQS 剖析
一.引言在JDK1.5之前,一般是靠synchronized关键字来实现线程对共享变量的互斥访问.synchronized是在字节码上加指令,依赖于底层操作系统的Mutex Lock实现.而从JDK1 ...
- CodeForces - 1042B
Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set o ...
- 如何在python的字符串中输入纯粹的{}
python的format函数通过{}来格式化字符串 >>> a='{0}'.format(123) >>> a ' 如果需要在文本中包含{}字符,这样使用就会报错 ...
- 2017 ACM暑期多校联合训练 - Team 9 1008 HDU 6168 Numbers (模拟)
题目链接 Problem Description zk has n numbers a1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk gen ...