首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CodeForces】445A - DZY Loves Chessboard(dfs)

【CodeForces】445A - DZY Loves Chessboard(dfs)

作者头像
FishWang
发布2025-08-26 20:45:26
发布2025-08-26 20:45:26
11600
代码可运行
举报
运行总次数:0
代码可运行

题目链接:点击打开链接

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

代码语言:javascript
代码运行次数:0
运行
复制
1 1
.

output

代码语言:javascript
代码运行次数:0
运行
复制
B

input

代码语言:javascript
代码运行次数:0
运行
复制
2 2
..
..

output

代码语言:javascript
代码运行次数:0
运行
复制
BW
WB

input

代码语言:javascript
代码运行次数:0
运行
复制
3 3
.-.
---
--.

output

代码语言:javascript
代码运行次数:0
运行
复制
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.

跟刚开始学dfs的题差不多,直接从第一个点开始放棋子就行了,依次往后扫描。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
#define MAX 100
int h,w;
char mapp[MAX+5][MAX+5];
int mx[] = {0,0,1,-1};
int my[] = {1,-1,0,0};
void dfs(int x,int y,bool flag)
{
	mapp[x][y] = flag ? 'B' : 'W';
	for (int i = 0 ; i < 4 ; i++)
	{
		int nx = x + mx[i];
		int ny = y + my[i];
		if (mapp[nx][ny] == '.')
			dfs(nx,ny,!flag);
	}
}
int main()
{
	scanf ("%d %d",&h,&w);
	for (int i = 1 ; i <= h ; i++)
		scanf ("%s",mapp[i]+1);
	for (int i = 1 ; i <= h ; i++)
	{
		for (int j = 1 ; j <= w ; j++)
		{
			if (mapp[i][j] == '.')
				dfs(i,j,true);
		}
	}
	for (int i = 1 ; i <= h ; i++)
		printf ("%s\n",mapp[i]+1);
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档