Codeforces445A_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.
解题报告
预处理图,B和W相间。
输入“-”让mmap[i][j]='-'
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char mmap[110][110];
int n,m;
int main()
{
int i,j;
while(~scanf("%d%d",&n,&m))
{
memset(mmap,0,sizeof(mmap));\
char c='B';
for(i=1; i<=n; i++)
{
if(i%2!=0)
c='B';
else c='W';
for(j=1; j<=m; j++)
{
mmap[i][j]=c;
if(c=='B')
c='W';
else c='B';
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>c;
if(c=='-')
mmap[i][j]=c;
}
}
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
cout<<mmap[i][j];
cout<<endl;
}
}
return 0;
}
Codeforces445A_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 ...
随机推荐
- [HDU3516] Tree Construction [四边形不等式dp]
题面: 传送门 思路: 这道题有个结论: 把两棵树$\left[i,k\right]$以及$\left[k+1,j\right]$连接起来的最小花费是$x\left[k+1\right]-x\left ...
- BZOJ 3462 DZY Loves Math II ——动态规划 组合数
好题. 首先发现$p$是互质的数. 然后我们要求$\sum_{i=1}^{k} pi*xi=n$的方案数. 然后由于$p$不相同,可以而$S$比较小,都是$S$的质因数 可以考虑围绕$S$进行动态规划 ...
- BZOJ3884 上帝与集合的正确用法 【欧拉定理】
题目 对于100%的数据,T<=1000,p<=10^7 题解 来捉这道神题 欧拉定理的一般形式: \[a^{m} \equiv a^{m \mod \varphi(p) + [m \ge ...
- 版本控制——hg教程
hg教程 引用来自官方网站的思维导图,来说明hg的使用规则:
- Codeforces Round #363 (Div. 2) C dp或贪心 两种方法
Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasy ...
- 有关UITableView--cell复用问题
近来用Tableview做了一个九宫格.过程中碰到了两个cell复用问题. 问题一: 在cell中为button添加addTarget点击事件时,出现后面的cell会重叠它前面cell的事件.代码 ...
- JavaScript (JS)基础:ECMAScript 浅析 (含Math基本方法解析)
浏览器端JavaScript的组成 ECMAScript:语法规范 DOM:Document Object Model 文档对象模型,操作页面元素 BOM:Browser Object Model ...
- ofbiz数据库表结构设计(3)- 订单ORDER
对于订单来说,主要的表就是ORDER_HEADER和ORDER_ITEM.ORDER_HEADER就是所谓的订单头,一条记录代表一条订单. ORDER_PAYMENT_PREFERENCE是订单的支付 ...
- 【Codeforces Round #518 (Div. 2)】
A:https://www.cnblogs.com/myx12345/p/9847588.html B:https://www.cnblogs.com/myx12345/p/9847590.html ...
- 【ztree】zTree节点增删改
今天遇到一个需求是对zTree的节点进行增删改,经过查阅资料总结如下: 效果: 完成增删改,要注意几个关键点: 使用 编辑功能,必须设置 setting.edit 中的各个属性 使用 编辑功能的事件回 ...