CodeForces - 445A - 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 <bits/stdc++.h>
#define MAX 102
using namespace std; char s[MAX][MAX];
char c[MAX][MAX];
int n,m; int main()
{
//ios::sync_with_stdio(false);
//freopen("data.txt","r",stdin);
while(cin>>n>>m){
memset(c,,sizeof(c));
for(int i=;i<n;i++) cin>>s[i];
for(int i=;i<n;i++) for(int j=;j<m;j++){
if(s[i][j]=='-') c[i][j]='-';
else{
if((i+j)%==) c[i][j]='W';
else c[i][j]='B';
}
}
for(int i=;i<n;i++) cout<<c[i]<<endl;
}
return ;
}
445A
CodeForces - 445A - DZY Loves Chessboard的更多相关文章
- CodeForces - 445A - DZY Loves Chessboard解题报告
对于这题本人刚开始的时候觉得应该用DFS来解决实现这个问题,但由于本人对于DFS并不是太熟,所以就放弃了这个想法: 但又想了想要按照这个要求实现问题则必须是黑白相间,然后把是字符是'B'或'W'改为' ...
- 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 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...
- 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)Codeforces445A DZY Loves Chessboard(纯实现题)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://codeforces.com/problemset/pro ...
- 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 ...
- Codeforces 444C DZY Loves Colors(线段树)
题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...
随机推荐
- null in JavaScript
C# String.IsNullOrEmpty Javascript equivalent https://stackoverflow.com/questions/5746947/c-sharp-st ...
- 【POJ 1011】 Sticks
[题目链接] http://poj.org/problem?id=1011 [算法] 深搜剪枝 首先我们枚举木棍的长度i,那么就有s/i根木棍,其中s为木棍长度的总和,朴素的做法就是对每种长度进行搜索 ...
- multimap的使用 in C++,同一个关键码存在多个值
#include <iostream> #include <string> #include <vector> #include <algorithm> ...
- Cosine Similarity of Two Vectors
#include <iostream>#include <vector>#include <cmath>#include <numeric> templ ...
- yrzl-cloud
- unity3D 使用欧拉角控制视野注意点
变量声明: public PlayerInput p; //表示控制代码用来获得用户是否按下 public float rotateSpeed = 50f; //旋转速度 private GameOb ...
- 4.Flask-alembic数据迁移工具
alembic是用来做ORM模型与数据库的迁移与映射.alembic使用方式跟git有点类似,表现在两个方面,第一个,alemibi的所有命令都是以alembic开头: 第二,alembic的迁移文件 ...
- C# 多线程系列(二)
传递数据给一个线程 通过函数或lambda表达式包一层进行传递. static void Main(string[] args) { Thread thread = new Thread(() =&g ...
- py2exe打包遇到的问题
py2exe打包python成.exe文件 打包过程和结果 1.创建setup脚本打包文件,其中设置打包的属性和方法.注意:尽量将被打包文件和此打包脚本放在同目录下(因为在尝试非同目录下时,出现了非可 ...
- ★Java语法(三)——————————变量常量
变量 1.命名规则:变量是标识符,遵循标识符命名规则: 2.作用范围: a 成员变量:作用范围是整个类: package 课上练习; public class 变量 { ; public static ...