HDU - 6122 Color the chessboard

Posted cjlhy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 6122 Color the chessboard相关的知识,希望对你有一定的参考价值。

HDU - 6122

我们能分析出来不可能列和行有连续一样的数字, 所以我们能得出图形是由ABABAB 和 BABABA 这两种形式的东西叠在一起构成的, 

要么是一列一列叠出来, 要么一行一行叠出来, 最后减去重复的, 也就是所有相邻数字都不一样的。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);

using namespace std;

const int N = 1e3 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-8;
const double PI = acos(-1);

template<class T, class S> inline void add(T &a, S b) a += b; if(a >= mod) a -= mod;
template<class T, class S> inline void sub(T &a, S b) a -= b; if(a < 0) a += mod;
template<class T, class S> inline bool chkmax(T &a, S b) return a < b ? a = b, true : false;
template<class T, class S> inline bool chkmin(T &a, S b) return a > b ? a = b, true : false;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, m, r[N], c[N], a[N];
char s[N][N];

int calc(int n) 
    int p = 0;
    for(int i = 1; i <= n; i++) 
        if(a[i] == -1) continue;
        p = i;
        break;
    
    if(!p) return 2;
    int now = (p & 1) ? a[p] : (a[p] ^ 1);
    for(int i = 1; i <= n; i++) 
        if(~a[i] && now != a[i]) return 0;
        now ^= 1;
    
    return 1;


int main() 
    int T; scanf("%d", &T);
    while(T--) 
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; i++) 
            scanf("%s", s[i] + 1);
        

        for(int i = 1; i <= n; i++) 
            for(int j = 1; j <= m; j++) 
                if(s[i][j] == R) a[j] = 0;
                else if(s[i][j] == B) a[j] = 1;
                else a[j] = -1;
            
            r[i] = calc(m);
        

        for(int j = 1; j <= m; j++) 
            for(int i = 1; i <= n; i++) 
                if(s[i][j] == R) a[i] = 0;
                else if(s[i][j] == B) a[i] = 1;
                else a[i] = -1;
            
            c[j] = calc(n);
        

        int wayr = 1;
        int wayc = 1;
        int wayrc = 0;

        int f0 = true, f1 = true;

        for(int i = 1; i <= n; i++) 
            for(int j = 1; j <= m; j++) 
                if(s[i][j] == ?) continue;
                int a = (i - 1) & 1;
                int b = (j - 1) & 1;
                int c = s[i][j] == R ? 0 : 1;
                if((a ^ b ^ c) != 0) f0 = false;
                if((a ^ b ^ c) != 1) f1 = false;
            
        

        wayrc = f0 + f1;

        for(int i = 1; i <= n; i++) 
            wayr = 1LL * wayr * r[i] % mod;
        

        for(int i = 1; i <= m; i++) 
            wayc = 1LL * wayc * c[i] % mod;
        

        printf("%d\n", ((wayr + wayc) % mod - wayrc + mod) % mod);
    
    return 0;


/*
*/

 

以上是关于HDU - 6122 Color the chessboard的主要内容,如果未能解决你的问题,请参考以下文章

hdu1556-Color the ball

HDU 1556 Color the ball

HDU——T 1556 Color the ball

hdu1556 Color the ball

hdu 1556 Color the ball (扫描线+树状数组)

HDU 6122 今夕何夕 数学公式 (2017"百度之星"程序设计大赛 - 初赛(A))