A. DZY Loves Chessboard
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.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#define ll long long
using namespace std;
int dir[][] = { {,},{-,},{,},{,-} };
int n, m;
vector<string> s(n);
void dfs(int x, int y, bool t)
{
s[x][y] = (t ? 'B' : 'W');
for (int i = ; i < ; i++)
{
int nx = x + dir[i][];
int ny = y + dir[i][];
if (nx>= && ny>= && nx+<=n && ny+<=m && s[nx][ny]=='.')
dfs(nx, ny, t ^ );
}
}
int main()
{
cin >> n >> m;
s.resize(n);
for (int i = ; i < n; i++)
cin >> s[i];
for (int i = ; i < n; i++)
{
for (int j = ; j < m; j++)
{
if (s[i][j] == '.') dfs(i, j, );
}
}
for (int i = ; i < n; i++)
{
if (i == n - )
cout << s[i];
else
cout << s[i] << endl;
}
//system("pause");
return ;
}
A. DZY Loves Chessboard的更多相关文章
- CodeForces445A DZY Loves Chessboard
A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏
DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input standard ...
- DZY Loves Chessboard
DescriptionDZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m ...
- cf445A DZY Loves Chessboard
A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #254 (Div. 2):A. DZY Loves Chessboard
A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CF 445A DZY Loves Chessboard
A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard —— dfs
题目链接: http://codeforces.com/problemset/problem/445/A 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...
- (CF)Codeforces445A DZY Loves Chessboard(纯实现题)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://codeforces.com/problemset/pro ...
- CodeForces - 445A - DZY Loves Chessboard
先上题目: A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input ...
随机推荐
- shell变量内字符替换和变量字符修改
vi test.sh a= #将${a}里的第一个123替换为321 b=${a//}; echo "echo variable a" echo $a echo "ech ...
- 二分-D - Can you solve this equation?
D - Can you solve this equation? Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you ...
- 初识消息队列--ActiveMq
消息队列 即MessageQueue,是一种消息中间件,在遇到系统请求量比较大的情况下,导致请求堆积过多无法及时返回,可以通过它进行异步的消息处理,从而缓解系统压力. ActiveMq ActiveM ...
- BBR在实时音视频领域的应用
小议BBR算法 BBR全称Bottleneck Bandwidth and RTT,它是谷歌在2016年推出的全新的网络拥塞控制算法.要说明BBR算法,就不能不提TCP拥塞算法. 传统的TCP拥塞控制 ...
- c#中转义字符\n和\r的区别
在c#中\n代表换行,\r代表回车,但\r是把后面的字符覆盖前面的,例: "1234\n567" 输出的是 1234 567 "1234\r567"输出的是 5 ...
- javascript增强typeof 对复杂类型的判断
js中有六种数据类型,包括五种基本数据类型(Number,String,Boolean,Undefined,Null),和一种复杂数据类型(Object). typeof 由于js中的变量是松散类型的 ...
- C++ 中字符串查找、字符串截取、字符串替换
参照:C++基础-string截取.替换.查找子串函数 1.字符串查找 s.find(s1) //查找s中第一次出现s1的位置,并返回(包括0) s.rfind(s1) //查找s中最后次出现s1的位 ...
- Android Studio的第一次运行
一.开发软件的下载 下载教程 https://blog.csdn.net/bzlj2912009596/article/details/87280191 下载地址 http://www.android ...
- 2D TOOLKIT备忘录
通过Clip名称更改动画片段 // 通过clip名称获取clip实例 tk2dSpriteAnimationClip clip = childrenAnimator.GetClipByName(&qu ...
- linux上安装git以及使用
用git --version命令检查是否已经安装 在CentOS5的版本,由于yum源中没有git,所以需要预先安装一系列的依赖包.在CentOS6的yum源中已经有git的版本了,可以直接使用yum ...