DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100).
Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.
Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
1 1 .
B
2 2 .. ..
BW WB
3 3 .-. --- --.
B-B --- --B
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
题意:
给出 n,m(1 ~ 150),代表有一个 N X M 的棋盘,- 代表这个地方不能填棋子,. 代表可以填充棋子。填充 W 和 B 两种棋子,任意相邻位置不能是相同的,输出这个棋盘的填充情况。
思路:
杂题。相间填充黑白棋是一定不会相邻的,有 - 的区别就是 - 就不显示这个位置的棋子而已。所以任意一个棋盘一定会存在两种解,不可能不存在的。一开始就读错题意了。最近智商有点降低。最后判断 (i + j )是否整除 2 来输出答案就好了。
AC:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char Map[105][105]; int main() { memset(Map, 0, sizeof(Map)); int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { scanf(" %c", &Map[i][j]); if (Map[i][j] == '.') { if ((i + j) % 2) Map[i][j] = 'B'; else Map[i][j] = 'W'; } } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { printf("%c", Map[i][j]); } printf("\n"); } return 0; }
相关推荐
动力源DZY-4850H整流器维修指导书,详细讲解了 动力源DZY4850H通讯电源的原理及维修指导,并提供了详细的原理图及电路 图,是非常好的维修指南
针对DZY100/30S煤矿用带式转载机在设计、制造和安装方面的要求,分析上下千斤顶设计选型、整机结构件受力分析、伸缩段受力和张力计算。为带式转载机整机的强度分析、优化设计提供参考依据。
python程序设计-dzy
介绍了一种煤巷高效快速掘进的DZY100/160/50型矿用带式转载机用制动系统的功能和结构特点,并根据该矿用带式转载机在煤巷高效快速掘进系统中的实际使用工况,确定了制动器的总体结构、制动扭矩以及安装方式等,在此基础...
非常好的QT 学习资粮 目录分明易懂 DZY 非常好的QT 学习资粮 目录分明易懂 DZY
DZY.exe
Python程序设计-dzy 自做
Python程序设计-dzy 模拟题
Python程序设计模拟题-dzy
图文混排--制作学校宣传板报说课演示dzy.ppt
DZY100/80/30S是煤矿充填面工作中可自移带式转载运输设备,根据煤矿充填工作要求对该带式转载机的输送带、托辊、电滚筒的选取及传动滚筒驱动力、输送带张力、拉紧力、拉紧行程等的确定进行了详细的分析和计算。
Python程序设计课件
针对目前充填工作面配套使用的带式转载机移动频繁...通过对DZY100/30S带式转载机的结构布置和设计中关键问题进行综合分析,介绍该设备主要技术参数和性能特点。实现充采均衡协调发展,为我国充填开采提供理想的配套设备。
端子排中间继电器用途、技术参数、外形及安装尺寸图。
设计滤波器,对模拟加噪语音信号进行低通滤波、高通滤波及带通滤波,并对滤波前后的信号时域、频域进行对比;
电源电路图看似复杂,很多新手在入门阶段就被电路图难住了,阅读电路图成为了非常困难的一件事。但实际上只要找到规律,阅读电路图并不是一件困难的事情。电路图由不同的电路结构组成,只要掌握了这些电路就能轻易地...
基于arm实现的密码锁。实现密码的预设定,解码功能。
转换PDF得到的.最终原作者.名字头都没删 这个就是根据PDF转的.要PDF的话可以联系我邮箱.txt主要是给那些想用手机看的人准备的. PDF的中文 英文都有我邮箱 dzy20@qq.com给我发邮件说明要...或者发邮件给我dzy20@qq.com
有天,吉丽拿着一道物理题目去问DZY,DZY很快就秒了这题,但是懒得算了,就让你来解决它。 题目描述 现在水平面上有一条无限长的光滑轨道,上面有n个小球(体积忽略),每个小球的质量都相同。现在这些小球在某些神奇...
UserDaoImpl.java