A. DZY Loves Chessboard
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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

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.

Examples
input

Copy
1 1
.
output

Copy
B
input

Copy
2 2
..
..
output

Copy
BW
WB
input

Copy
3 3
.-.
---
--.
output

Copy
B-B
---
--B
Note

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的矩阵,用B和W填充‘.’,且相邻的位置不可以相同。

【分析1】

看做一个二分图,经典染色法
 


【代码1】

#include<cstdio>
#include<cstdlib>
using namespace std;
const int N=105;
int n,m,ans,dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
char mp[N][N];
void dfs(int x,int y,bool t){
mp[x][y]=(t?'B':'W');
for(int i=0;i<4;i++){
int nx=x+dir[i][0];
int ny=y+dir[i][1];
if(nx<1||ny<1||nx>n||ny>m||mp[nx][ny]!='.') continue;
dfs(nx,ny,t^1);
}
}
inline void Init(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",mp[i]+1);
}
inline void Solve(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]=='.') dfs(i,j,1);
}
}
for(int i=1;i<=n;i++) puts(mp[i]+1);
}
int main(){
Init();
Solve();
return 0;
}

 

【分析2】

规律:若当前位置为’.’,就i + j 时为奇数时输出W,反之输出B;若当前位置为’-’,直接输出
 


【代码2】

#include<cstdio>
#include<cstdlib>
using namespace std;
const int N=105;
int n,m;
char mp[N][N];
inline void Init(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",mp[i]+1);
}
inline void Solve(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]=='-') printf("-");
else printf("%s",(i+j)&1?"W":"B");
}
puts("");
}
}
int main(){
Init();
Solve();
return 0;
}

 

CF 445A DZY Loves Chessboard的更多相关文章

  1. CodeForces - 445A - DZY Loves Chessboard

    先上题目: A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input ...

  2. CodeForces - 445A - DZY Loves Chessboard解题报告

    对于这题本人刚开始的时候觉得应该用DFS来解决实现这个问题,但由于本人对于DFS并不是太熟,所以就放弃了这个想法: 但又想了想要按照这个要求实现问题则必须是黑白相间,然后把是字符是'B'或'W'改为' ...

  3. Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard —— dfs

    题目链接: http://codeforces.com/problemset/problem/445/A 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...

  4. CodeForces445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. 周赛-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 ...

  6. DZY Loves Chessboard

    DescriptionDZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m ...

  7. cf445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  8. 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 ...

  9. CF 445A(DZY Loves Chessboard-BW填充)

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. 解决 PathVariable annotation was empty on param 0.

    今天在写网关关于远程调用Feign的时候报的一个错误,PathVariable注解为空.仔细看了一下代码发现问题出在用@PathVariable注解的时候 @PathVariable Integer ...

  2. hibernate.cfg配置mysql方言

    hibernate自动建表,mysql高版本不支持 type=InnoDB 中的type关键字. 应该使用engine关键字 而非type 所以需要在hibernate.cfg.xml中配置方言.否则 ...

  3. 一款基于 Android 开发的离线版的 MM 图片浏览 App

    一款离线版的 MM 图片浏览 App,有点类似掌上百度的图片专栏应用.图片采用瀑布流展示方式,点击图片集,支持左右手势滑动切换图片:支持放大缩小功能. 实现功能:1)图片完全离线,不耗个人 GPRS ...

  4. bash: /usr/bin/npm: No such file or directory

    一个整得很烂了的Ubuntu服务器, 各种问题乱出. npm老是升不到最新版(一直显示1.4),于是我干脆删了, 结果再去装却装不上了, 如果用apt-get install npm安装, 就得到如下 ...

  5. Sql Server 跨服务器连接

    用openrowset连接远程SQL或插入数据 --如果只是临时访问,可以直接用openrowset --查询示例 select * from openrowset('SQLOLEDB', 'sql服 ...

  6. MySQL 高性能表设计规范

    良好的逻辑设计和物理设计是高性能的基石, 应该根据系统将要执行的查询语句来设计schema, 这往往需要权衡各种因素. 一.选择优化的数据类型 MySQL支持的数据类型非常多, 选择正确的数据类型对于 ...

  7. 8 -- 深入使用Spring -- 1...3 容器后处理器

    8.1.3 容器后处理器(BeanFactoryPostProcessor) 容器后处理器负责处理容器本身. 容器后处理器必须实现BeanFacotryPostProcessor接口.实现该接口必须实 ...

  8. 使用InternetGetConnectedState判断本地网络状态(C#举例)

    函数原型:函数InternetGetConnectedState返回本地系统的网络连接状态. 语法: BOOL InternetGetConnectedState( __out LPDWORD lpd ...

  9. 【NodeJS】http-server.cmd

    npm install http-server @echo off  start cmd /k "D:\Program Files\nodejs\node_global\http-serve ...

  10. Unity Shader 自定义纹理坐标变量写法

    Properties { _R(,)) = 1.0 _ColorTex("ColorTex (RGB)", 2D) = "red" {} struct Inpu ...