Codeforces 1333 A. Little Artem
[1][1]格子是W,其余都是B即可
-
题目:
nxm的网格,只能是黑白两种颜色,有至少一个相邻格子为白色的黑色数目为B,至少一个相邻格子是黑色的数目是W;
输入n,m。输出一种B = W + 1的涂色方法。 -
题解:
分类讨论n,m是奇偶的情况即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
typedef long long ll;
const int N = 3e6 + 105;
const int mod = 998244353;
const double Pi = acos(- 1.0);
const int INF = 0x3f3f3f3f;
const int G = 3, Gi = 332748118;
//
//main()
ll T, n, m, x, y;
ll a[N];
ll res[150][150];
int main()
{
scanf("%lld",&T);
while(T --){
scanf("%lld%lld",&n,&m);
for(int i = 1; i <= n; ++ i){
for(int j = 1; j <= m; j += 2){
res[i][j] = 1;
res[i][j + 1] = 0;
}
}
if(m % 2 == 0) {
res[n - 1][m] = 1;
res[n - 1][m - 1] = 0;
res[n][m] = 1;
}
else{
for(int i = 1; i <= n; i += 2){
res[i][m] = 1;
res[i + 1][m] = 0;
}
if(n % 2 == 0) res[n][2] = 1;
}
for(int i = 1; i <= n; ++ i){
for(int j = 1; j <= m; ++ j){
if(res[i][j]) printf("B");
else printf("W");
}
printf("\n");
}
}
return 0;
}