首页 > 其他 > 详细

Codeforces 1333 A. Little Artem

时间:2020-04-29 23:22:33      阅读:462      评论:0      收藏:0      [点我收藏+]

技术分享图片
技术分享图片

  • 题目:
    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;
}

Codeforces 1333 A. Little Artem

原文:https://www.cnblogs.com/A-sc/p/12805787.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!