【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 ...
随机推荐
- linux查看tomcat日志
声明:以上内容均为转载,个人对这块知识搜罗之后放在一起,非原创,以后这块有问题还会继续添加. Tomcat 日志分为下面5类: catalina . 相当命令行输出日志 localhost . 相当于 ...
- Mysql 插入时间时报错Incorrect datetime value: '' for column 'createtime'
在网上找了很多方法总结如下: 1.MySQL驱动版本的问题.这种一般是在mYSQL版本更新了之后才会报错.解决方法在jdbc里添加“&useOldAliasMetadataBehavior=t ...
- python3.6.4的importlib模块重载用法
了解:模块的重载 考虑到性能的原因,每个模块只被导入一次,放入字典sys.module中,如果你改变了模块的内容,你必须重启程序,python不支持重新加载或卸载之前导入的模块, 有的同学可能会想到直 ...
- Jupyter Notebook Tutorial: Introduction, Setup, and Walkthrough
Jupyter Notebook Tutorial: Introduction, Setup, and Walkthrough YouTube https://www.youtube.com/watc ...
- 小记 百度地图 soso地图 经纬度偏移
项目里遇到了这么个问题,数据库原有数据是微信上用的,所以是soso地图坐标, 但是现在要做百度地图,坐标偏移严重,网上找了也没说偏移多少,自己手动测试10多分钟,得到个大概值,反正差不多就行了. so ...
- mysql 距离函数
要有超级权限 SET GLOBAL log_bin_trust_function_creators = 1;DELIMITER $$CREATE DEFINER=`root`@`localhost` ...
- bzoj1190 [HNOI2007]梦幻岛宝珠
传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1190 [题解] 首先,我们把所有物品都分解成$a\times 2^b$的形式,然后把物品按 ...
- 【BZOJ】3786: 星系探索
[题意]给定一棵带点权树,三种操作: 1.询问点x到根的路径和 2.子树x内的点权加定值y 3.将点x的父亲更换为y,保证仍是树. [算法]平衡树(fhq-treap) [题解] 将树的dfs序作为序 ...
- 20155315 2016-2017-2 《Java程序设计》第六周学习总结
教材学习内容总结 第10章 输入与输出 1.串流设计的概念 从应用程序角度看,将数据从来源取出,可以使用输入串流,将数据写入目的地,可以使用输出串流:在Java中,输入串流代表对象为java.io.I ...
- CodeForces - 1042B
Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set o ...