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 ...
随机推荐
- 剑指offer42:翻转单词顺序 VS 左旋转字符串(更高效、简便的解法)
题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变.为简单起见,标点符号和普通字母一样处理.例如输入字符串"I am a student." ,则输出" ...
- BZOJ3166 [Heoi2013]Alo 【可持久化trie树 + 二分 + ST表】
题目 Welcome to ALO ( Arithmetic and Logistic Online).这是一个VR MMORPG , 如名字所见,到处充满了数学的谜题. 现在你拥有n颗宝石,每颗宝石 ...
- Python之数据结构:字符串
一.字符串类型 1.普通字符串 s1='abef\neiwo' print s1 print type(s1) 结果: abef eiwo <type 'str'> 2.原始字符串 s2= ...
- String 类详解
StringBuilder与StringBuffer的功能基本相同,不同之处在于StringBuilder是非线程安全的,而StringBuffer是线程安全的,因此效率上StringBuilder类 ...
- 上传相同文件名的时候不能触发change事件的解决方案
方法一 在上传完文件之后,将<input type="file" /> 的值置为null,即可. 方法二 在上传完文件之后替换dom 方法三 在上传完文件之后刷新页面
- Connect(bzoj 1948)
Description 给定一个R*C大小的迷宫,其中R,C均为奇数 迷宫中坐标为两个奇数的点不能通过,称为障碍,迷宫中其他不能通过的点统称为墙壁 坐标为两个偶数的点可以通过,称为房间,迷宫中其他可通 ...
- 【转】Java进阶之路
1. 引言 搞Java的弟兄们肯定都想要达到更高的境界,用更少的代码解决更多的问题,用更清晰的结构为可能的传承和维护做准备.想想当初自己摸着石头过河,也看过不少人介绍的学习路线,十多年走过来多少还 ...
- sql2008百万级数据排除重复信息
--高性能排除重复select userid from table where userid in ( select userid from ( select userid, row_number() ...
- Cookies设置,获取,删除
之前的博客,整理了下Session的存储方式和原理http://www.cnblogs.com/chinaagan/p/3200456.html. 本篇再次整理下Cookies的使用和原理. 参考博客 ...
- Bzoj1974 [Sdoi2010]auction 代码拍卖会
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 375 Solved: 151 Description 随着iPig在P++语言上的造诣日益提升,他形成 ...