Codeforces Round #254 (Div. 2):A. DZY Loves Chessboard
1 second
256 megabytes
standard input
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.
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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; const int M = 1000 + 5;
char str[M][M];
int a, b; int main()
{
while(scanf("%d%d", &a, &b)!=EOF)
{
memset(str, 0, sizeof(str));
for(int i=1; i<=a; i++)
for(int j=1; j<=b; j++)
cin>>str[i][j];
for(int i=1; i<=a; i++)
for(int j=1; j<=b; j++)
{
if(str[i][j]=='.')
{
if((i+j)%2==0)
str[i][j]='B';
else
str[i][j]='W';
}
}
for(int i=1; i<=a; i++)
{
for(int j=1; j<=b; j++)
cout<<str[i][j];
cout<<endl;
}
} return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
Codeforces Round #254 (Div. 2):A. DZY Loves Chessboard的更多相关文章
- Codeforces Round #254 (Div. 2):B. DZY Loves Chemistry
B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #FF (Div. 2):C. DZY Loves Sequences
C. DZY Loves Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash
A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round 254 (Div. 2)
layout: post title: Codeforces Round 254 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #254 (Div. 1) C. DZY Loves Colors 线段树
题目链接: http://codeforces.com/problemset/problem/444/C J. DZY Loves Colors time limit per test:2 secon ...
- Codeforces Round #254 (Div. 1) D. DZY Loves Strings hash 暴力
D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings ...
- Codeforces Round #254 (Div. 1) C. DZY Loves Colors 分块
C. DZY Loves Colors 题目连接: http://codeforces.com/contest/444/problem/C Description DZY loves colors, ...
- Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题
A. DZY Loves Physics 题目连接: http://codeforces.com/contest/444/problem/A Description DZY loves Physics ...
- Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard —— dfs
题目链接: http://codeforces.com/problemset/problem/445/A 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...
随机推荐
- (hdu 7.1.8)Quoit Design(最低点——在n一个点,发现两点之间的最小距离)
主题: Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 23设计模式(3):Abstract Factory模式
定义:要创建一组相关或依赖对象提供一个接口,而你并不需要指定其具体类别. 类型:创建一个类模型 类图: 抽象工厂模式与工厂方法模式的差别 抽象工厂模式是工厂方法模式的升级版本号,他用来创建一组相关或者 ...
- javascript推断的浏览器类型
<script> window["MzBrowser"]={};(function() { if(MzBrowser.platform) return; var ua ...
- OCP-1Z0-051-名称解析-文章7称号
7. Which two statements are true regarding the USING and ON clauses in table joins? (Choose two.) A ...
- 【NO.3】 c program to caculate and display sum of two matrix
source code: #include "stdafx.h" /* display sum of two matrix*/ int _tmain(int argc, _TCHA ...
- C++primer读书笔记9-转换和类类型
有时指定自己的类类型来表示某些类型的数据,如SmallInt,然后在为了便于计算将指定一个转换算,类类型,在某些情况下,自己主动转换为指定的类型 <1>转换操作符 operator typ ...
- SPOJ PT07X Vertex Cover
题目意思: 一棵树,找到最少的点能覆盖到所有的边,(也就是每条边俩端 至少有一个在你找到的集合): 解法:每条边只能被俩个点中的一个,或全部覆盖所以我们有树形DP来解: DP[num][flag]// ...
- linux根据该文件夹的读取权限和权限运行差异
假设你linux下使用ls.细心的你会发现居然夹有权限运行.例如: drwxrwxr-x 11 cl cl 4096 9 25 14:22 ./ drwxr-xr-x 49 cl cl 4096 1 ...
- Nginx各版本的区别
Nginx官网提供了三个类型的版本Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版Stable version:最新稳定版,生产环境上建议使用的版 ...
- 汉诺塔问题的java递归实现
import java.util.Scanner; public class Hanoi { int count=0; public void hanoi(int n,char A,char B,ch ...