Problem

题目简述

给你一个 \(n \times m\) 的方格,构造一个方案,使得方案中 \(B = W + 1\)。

\(B\):相邻的格子有至少一个白色格子的黑色格子的个数。

\(W\):相邻的格子有至少一个黑色格子的白色格子的个数。

思路

分奇偶讨论。

  • \(n \times m\) 是偶数:构造一张黑、白相间的矩阵,左上角填为白色,黑色方块的数量相同。

  • \(n \times m\) 是奇数:构造一张黑、白相间的矩阵,左上角填为黑色,黑白快数量相同。

代码

#include <bits/stdc++.h>

using namespace std;

int T, n, m;

int main() {

	scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
if((n & 1) && (m & 1)) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if((i + j) & 1) printf("%c", 'W');
else printf("%c", 'B');
}
puts("");
}
}
else {
printf("%c", 'B');
for(int i = 2; i <= m; i++) {
if((i + 1) & 1) printf("%c", 'B');
else printf("%c", 'W');
}
puts("");
for(int i = 2; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if((i + j) & 1) printf("%c", 'B');
else printf("%c", 'W');
}
puts("");
}
}
}
return 0;
}

CF1333A [Little Artem]的更多相关文章

  1. codeforces 442C C. Artem and Array(贪心)

    题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. cf442C Artem and Array

    C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  4. Codeforces 442C Artem and Array (看题解)

    Artem and Array 经过分析我们能发现, 如果对于一个a[ i ] <= a[ i + 1 ] && a[ i ] <= a[ i - 1 ]可以直接删掉. 最 ...

  5. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学

    C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...

  6. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组

    E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...

  7. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟

    D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...

  8. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟

    C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...

  9. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题

    B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...

  10. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题

    A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...

随机推荐

  1. 【Nginx】Nginx访问静态资源

    Nginx访问静态资源 即通过IP:端口/文件名 访问文件实现. 修改Nginx配置 location / { # root html; # index index.html index.htm; a ...

  2. HTB靶场之Sandworm

    准备: 攻击机:虚拟机kali. 靶机:Sandworm,htb网站:https://www.hackthebox.com/,靶机地址:https://app.hackthebox.com/machi ...

  3. Python数据分析易错知识点归纳(五):横向对比

    五.横向对比 排序 # 列表 a.sort() # 修改原列表,返回值为None!!!!!这里很容易出错 sorted(a) # 生成新的列表 # 嵌套列表的排序(若是对字典排序,需先用list()转 ...

  4. Anaconda 使用时,conda activate 失败

    今天使用一台电脑上新安装的 anaconda 时,运行 conda activate, 出现如下报错: 错误提示中,说要把 . C:\ProgramData\Anaconda3\etc\profile ...

  5. Linux 脚本:shell

    # 以脚本所在目录作为脚本执行时的当前路径. -P 选项寻找物理上的地址,忽略软连接. SCRIPT_DIR=$(cd $(dirname $0); pwd -P) # 在任意位置执行自己的可执行程序 ...

  6. 学习狂神Spring5_课堂笔记(更新中)

    Spring 简介 spring,英文单词为春天,表示为软件行业带来了春天. 2002年,首次推出了Spring框架的雏形:interface21框架.官网为:www.interface21.io但是 ...

  7. Django: Invalid block tag on line 5: 'static', expected 'endblock'. Did you forget to register or load this tag?

    错误释义:在第5行中无效的块标签:'static',期望的'endblock'.你忘记登记或装载这个标签了吗? 错误原因:没有引入static文件 {% extends 'base.html' %} ...

  8. vim 配色调整

    ~/.vimrc " Configuration file for vim set modelines=0 " CVE-2007-2438 set number " se ...

  9. jQuery项目的小技巧

    1.返回顶部按钮 你可以利用 animate 和 scrollTop 来实现返回顶部的动画,而不需要使用其他插件. // Back to top // Back to top $('a.top').c ...

  10. 深入浅出 Typescript

    TypeScript 是 JavaScript 的一个超集,支持 ECMAScript 6 标准(ES6 教程). TypeScript 由微软开发的自由和开源的编程语言. TypeScript 设计 ...