题解

最近一遇到神仙题一卡就好久……做点水题滋养一下自己吧= =

显然我们发现放一个方块的奇偶性不会改变,所以格子如果黑格子是奇数,那么就是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 俄罗斯方块的更多相关文章

  1. 51nod 1851俄罗斯方块(trick)

    题目大意:给出一个黑白图,你可以选定一个俄罗斯方块的区域,黑白翻转,问能否变成白图 比较trick的题目, 首先可以想到,奇数个1肯定是无解的,所以考虑偶数个1 可以先讨论n是2的情况 当n为2时,其 ...

  2. 51nod 1851 俄罗斯方块

    玩过俄罗斯方块?那你知道俄罗斯方块共有七种吧(其实只有五种) 给一个黑白图,每次能将某些区域的格子黑白反转,至于某些区域的意思嘛,就是俄罗斯方块形状的区域咯(可水平翻转.上下翻转.旋转) 求能否将图变 ...

  3. 还是俄罗斯方块之android版

    前面的,口水话 请直接跳过. 虽然现在不比以前了 也没多少人气了,放到首页 都不到几百的点击量.也许博客园整体水平也是在往水的方向发展.不谈那些了,哥也曾经辉煌过 有过一天上千的点击量 ,哥也曾经有过 ...

  4. x01.Tetris: 俄罗斯方块

    最强大脑有个小孩玩俄罗斯方块游戏神乎其技,那么,就写一个吧,玩玩而已. 由于逻辑简单,又作了一些简化,所以代码并不多. using System; using System.Collections.G ...

  5. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

  6. 51Nod 1268 和为K的组合

    51Nod  1268  和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...

  7. 51Nod 1428 活动安排问题

    51Nod   1428  活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...

  8. 51Nod 1278 相离的圆

    51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...

  9. 俄罗斯方块C#版

    using System; using System.Windows.Forms; using System.Drawing; using System.Media; class me : Form ...

随机推荐

  1. python---重点(设计模式)

    前戏:设计模式简介 设计模式是面向对象设计的解决方案,是复用性程序设计的经验总结.(与语言无关,任何语言都可以实现设计模式) 设计模式根据使用目的的不同而分为创建型模式(Creational Patt ...

  2. COGS 1516. 棋盘上的车

    COGS 1516. 棋盘上的车 http://www.cogs.pro/cogs/problem/problem.php?pid=1516 ☆   输入文件:rook.in   输出文件:rook. ...

  3. A Gentle Guide to Machine Learning

    A Gentle Guide to Machine Learning Machine Learning is a subfield within Artificial Intelligence tha ...

  4. Web API: Client: Call a Web API from a .net client

    原文地址: http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client 翻译地址:h ...

  5. 20155233 2016-2017-2 《Java程序设计》第6周学习总结

    20155233 2016-2017-2 <Java程序设计>第6周学习总结 学习目标 理解流与IO 理解InputStream/OutPutStream的继承架构 理解Reader/Wr ...

  6. window环境下使用sbt编译spark源码

    前些天用maven编译打包spark,搞得焦头烂额的,各种错误,层出不穷,想想也是醉了,于是乎,换种方式,使用sbt编译,看看人品如何! 首先,从官网spark官网下载spark源码包,解压出来.我这 ...

  7. HDU 1160 FatMouse's Speed (最长上升子序列)

    题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...

  8. HDU 4311 Meeting point-1 求一个点到其它点的曼哈顿距离之和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4311 解题报告:在一个平面上有 n 个点,求一个点到其它的 n 个点的距离之和最小是多少. 首先不得不 ...

  9. jenkins 入门教程(上)【转】

    转自:https://www.cnblogs.com/yjmyzz/p/jenkins-tutorial-part-1.html jenkins是一个广泛用于持续构建的可视化web工具,持续构建说得更 ...

  10. c# CTS 基础数据类型笔记

    C#中的基础数据类型并没有内置于c#语言中,而内置于.net freamework. C#有15个预定义类型,其中13个是值类型,两个是引用类型(string和object) 一.值类型 值类型 数据 ...