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. Mybatis最入门---数据库的下载与安装

    [一步是咫尺,一步即天涯] 近期.因为工作进度调整,之前的Spring教程就先临时告一段落了,兴许找个时间继续更新,假设有那位看官想了解某个内容的,敬请留言,大家一起学习. 作为数据库工具的使用开篇. ...

  2. thinkphp并发 阻塞模式与非阻塞模式

    结构代码 public function index(){ $fp = fopen("lock.txt", "w+"); if(flock($fp,LOCK_E ...

  3. 条理清晰的搭建SSH环境之整合Struts和Spring

    上文说到搭建SSH环境所需三大框架的jar包,本篇博客将通过修改配置文件整合Struts和Spring,下篇博客整合Hibernate和Spring即可完成环境搭建. 1.声明bean,新建TestA ...

  4. eclipse中去掉validate的方法

    昨天在右击项目想选择refresh的时候一不小心选择了validate,就发现target包出现了红色的叉号.当时觉得反正项目运行没有什么异常,就这么凑合了一天半多. 后来,当我改jsp的时候从< ...

  5. Objective-C语法之NSPredicate的使用

    正则表达式判断手机号码和电话号码的方法: #import <Foundation/Foundation.h> /** 正则判断手机号码地址格式 */ BOOL isMobileNumber ...

  6. JavaBridge

    有的时候我们需要在PHP里调用JAVA平台封装好的jar包里的class类和方法 一般的做法是采用php-java-bridge做桥接 1.实现原理: 先打开java的一个监听端口,php调用java ...

  7. 如何用BarTender将日期变量和序列号变量放一起打印成条码?

    刚接触BarTender 2016的小伙伴们可能对条码的数据源还不太搞的定,例如有时需要将日期变量和序列号变量放一起打印成条码,那如何简单达到目的呢?下面,小编教大家解决这一问题的三大步骤. 1.在B ...

  8. VS常用快捷鍵

    折疊所有方法 Ctrl +M +M 折疊單個方法 Ctrl +M +O 折疊單個方法

  9. Go之类型判断

    boy := util.Boy{util.Person{"Eric", 19, "boy"}, "1"} var boyClone inte ...

  10. ios开发之--UITableView中的visibleCells的用法

    先上图: 具体代码如下: #import "ViewController.h" @interface ViewController ()<UITableViewDelegat ...