HDU-6122 Color the chessboard(思维题)
来源:互联网 发布:linux 内核驱动开发 编辑:程序博客网 时间:2024/04/30 01:55
传送门:HDU-6122
有一个n行m列的棋盘,最初每个位置是指定的红色或蓝色或白色。你要将白色的位置染成红色或蓝色,使得对于任意一个长宽均为偶数的连续子棋盘,其中红色和蓝色的位置数相等,求方案数模998244353。1≤n,m≤103。
即每个2*2连续子矩阵红蓝数量相等。令红为1,蓝为0,如果让把所有格子按行号与列号的和的奇偶性反色(如果是奇数则颜色取反),则转化为每个2*2子矩阵对角线的和相等。发现这个条件当且仅当每行都是全1或全0,或者每列都是全1或全0,讨论一下就好了。
题解如上 = =。。。反正被这道题虐智商了(感觉全世界都会写
#include<bits/stdc++.h>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;typedef long long LL;typedef pair<int, int> PII;const int inf = 0x3f3f3f3f;const int MX = 1e3 + 5;const int mod = 998244353;char str[MX];int mr[MX],mc[MX];int main() { int T, n, m; //freopen("in.txt", "r", stdin); scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) mr[i] = 0; for (int i = 1; i <= m; i++) mc[i] = 0; int r = n, c = m,mark=0; for (int i = 1; i <= n; i++) { scanf("%s", str + 1); for (int j = 1; j <= m; j++) if (str[j] != '?') { int col = str[j] == 'R' ? 2 : 1; if (i + j & 1) col = 3 - col; if(mr[i]&&mr[i]!=col) r=-1; else if(!mr[i]) mr[i]=col,r--; if(mc[j]&&mc[j]!=col) c=-1; else if(!mc[j]) mc[j]=col,c--; if(mark>=0){ //去重,如果mark==0,则会有2次重复(全0和全1) //如果mark==1,则只会由1次重复(要么全0要么全1) //如果mark==-1,这种情况出现在即有0又有1时,则不会出现全0或全1 if(mark==0) mark=col; else if(mark!=col) mark=-1; } } } int ans = 0; if (r >= 0) { int t = 1; while (r--) t = t * 2 % mod; (ans += t) %= mod; } if (c >= 0) { int t = 1; while (c--) t = t * 2 % mod; (ans += t) %= mod; } if (mark >= 0) ans = (ans - (mark ? 1 : 2) + mod) % mod; printf("%d\n", ans); } return 0;}
阅读全文
0 0
- HDU-6122 Color the chessboard(思维题)
- HDU 6122 Color the chessboard【思维】
- hdu-6122 Color the chessboard 思维
- HDU 6122 Color the chessboard(机智)
- [HDU 6122] Color the chessboard
- hdu 6122 Color the chessboard
- 思维 hdu 5100 (chessboard)
- 【HDU】-5100-Chessboard(思维)
- 解题报告:HDU_6122 Color the chessboard (计数)
- hdu 1556 Color the ball(基础题)
- Codeforces 349 B Color the Fence (思维+贪心)
- CodeForces - 349B Color the Fence (思维)
- hdu(1556)Color the ball
- HDU 1556 Color the ball (模拟)
- HDU 1556 Color the ball(BIT)
- Color the ball HDU
- Color the ball HDU
- Color the Ball HDU
- 迭代器
- 网易编程题 等差数列
- 简述Java类的“初始化”
- 『区块链+TR069协议』打造全球通用区块链物联网
- SQL---Lpad()函数,Rpad()函数,数据库
- HDU-6122 Color the chessboard(思维题)
- 离职的日子
- Frogger(Floyd变形)
- BalalaPower个人解题心得
- hive on tez详细配置和运行测试
- 运维发展分析
- 使用ChatterBotCorpusTrainer时ubuntu_dialogs.tgz应该存放的路径
- footer 始终位于页面的底部
- 水题笔记: virus [拓扑排序]