zoukankan      html  css  js  c++  java
  • 【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('
    ')
    #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();
        }
    }
    
  • 相关阅读:
    解方程
    十进制快速幂
    comb
    题单解题记录-POJ题目分类推荐 (很好很有层次感)
    算法题离谱错误合集
    VMware-Ubuntu16.04踩坑解决记录
    2020牛客多校赛第三场
    需学习的博客地址
    错误记录
    可持久化线段树 区间第k大/小
  • 原文地址:https://www.cnblogs.com/ivorysi/p/9182994.html
Copyright © 2011-2022 走看看