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.
MD,今天写这道题目的时候,想的太简单了,被一类数据搞得体无完肤。。。
50 50
.........................--..................-....
............................................-.....
..-.....................................-.........
...........................-......................
........-.....................-...................
..................................................
.......-......-...................................
...-..................-.......................-...
.....-......-...............................-.....
...-................-...-..............
BWBWBWBWBWBWBWBWBWBWBWBWB--BWBWBWBWBWBWBWBWBW-BWBW
WBWBWBWBWBWBWBWBWBWBWBWBWBWWBWBWBWBWBWBWBWBW-BWBWB
BW-WBWBWBWBWBWBWBWBWBWBWBWBBWBWBWBWBWBWB-BWBWWBWBW
WBWBWBWBWBWBWBWBWBWBWBWBWBW-BWBWBWBWBWBWBWBWBBWBWB
BWBWBWBW-WBWBWBWBWBWBWBWBWBWWB-BWBWBWBWBWBWBWWBWBW
WBWBWBWBWBWBWBWBWBWBWBWBWBWBBWBWBWBWBWBWBWBWBBWBWB
BWBWBWB-BWBWBW-WBWBWBWBWBWBWWBWBWBWBWBWBWBWBWWBWBW
WBW-WBWBWBWBWBWBWBWBWB-BWBWBBWBWBWBWBWBWBWBWBB-BWB
BWBWB-BWBWBW-WBWBWBWBWBWBWBWWBWBWBWBWBWBWBWB-WBWBW
WBW-WBWBWBWBWBWBWBWB-BWB-BWBBWBWBWBWBWBWBWB...
BWBWBWBWBWBWBWBWBWBWBWBWB--WBWBWBWBWBWBWBWBWB-BWBW
WBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB-BWBWB
BW-WBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBW-WBWBWBWBW
WBWBWBWBWBWBWBWBWBWBWBWBWBW-WBWBWBWBWBWBWBWBWBWBWB
BWBWBWBW-WBWBWBWBWBWBWBWBWBWBW-WBWBWBWBWBWBWBWBWBW
WBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB
BWBWBWB-BWBWBW-WBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBW
WBW-WBWBWBWBWBWBWBWBWB-BWBWBWBWBWBWBWBWBWBWBWB-BWB
BWBWB-BWBWBW-WBWBWBWBWBWBWBWBWBWBWBWBWBWBWBW-WBWBW
WBW-WBWBWBWBWBWBWBWB-BWB-BWBWBWBWBWBWBWBWBW... 一开始想的就是把每个格子按顺序填写好就没问题吧,这就是问题,当然不对了,在有拐角的地方,按顺序,就是错误!!
好吧,Json的方法,就是在已经打好的答案里填写字母,就OK,(这种方法很变态啊,积累吧)
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int max_size = ; int main()
{
int row, col;
int graph[max_size][max_size];
int vis[max_size][max_size]; for(int i = ; i < max_size; i++)
{
for(int j = ; j < max_size; j++)
{
if((i+j) % == )
graph[i][j] = ;
else
graph[i][j] = ;
}
}
scanf("%d %d%*c", &row, &col); for(int i = ; i < row; i++)
{
for(int j = ; j < col; j++)
{
char a = getchar();
if(a == '-')
graph[i][j] = -;
}
getchar();
} for(int i = ; i < row; i++)
{
for(int j = ; j < col; j++)
{
if(graph[i][j] == )
printf("B");
else if(graph[i][j] == )
printf("W");
else
printf("-");
}
puts("");
}
return ;
}
代码
CodeForces445A DZY Loves Chessboard的更多相关文章
- (CF)Codeforces445A DZY Loves Chessboard(纯实现题)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://codeforces.com/problemset/pro ...
- 周赛-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 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...
- CodeForces - 445A - DZY Loves Chessboard
先上题目: A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input ...
- A. DZY Loves Chessboard
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m columns. So ...
随机推荐
- WIN7 + IIS7 Service Unavailable HTTP Error 503. The service is unavailable.
在win7上开启IIS功能,进行网站发布. 但是开启IIS之后,打开默认网站都打不开,显示 Service Unavailable HTTP Error 503. The service is una ...
- 深入理解javascript原型和闭包(14)——从【自由变量】到【作用域链】
先解释一下什么是“自由变量”. 在A作用域中使用的变量x,却没有在A作用域中声明(即在其他作用域中声明的),对于A作用域来说,x就是一个自由变量.如下图 如上程序中,在调用fn()函数时,函数体中第6 ...
- 利用pg_stat_activity进行问题排查
pg_stat_activity是一个非常有用的视图,可以帮助排查pg的一些问题(如连接数目过多问题).pg_stat_activity每行展示的是一个“process”的相关信息,这里的“proce ...
- 安装yii2时出错 Invalid Parameter – yii\base\InvalidParamException
最近composer安装yii2的时候页面报了这个错,应该是bower的前端资源位置改变的缘故! Invalid Parameter – yii\base\InvalidParamException ...
- iOS中常用属性的关键字的使用说明
属性关键字的作用 现在我们iOS开发中,基本都是使用ARC(自动引用计数)技术,来编写我们的代码.因此在属性property中我们经常使用的关键字有strong,weak,assign,copy,no ...
- can't debug windows service in win7 64bit
if encount below error: Solution: run the command “vsdiag_regwcf.exe -i” as admin in C:\Program File ...
- HTML5 data-* 属性
HTML5 data-* 属性 jQuery Mobile 依赖 HTML5 data-* 属性来支持各种 UI 元素.过渡和页面结构.不支持它们的浏览器将以静默方式弃用它们.表 2 显示如何使用 d ...
- Linux C 字符函数 getchar()、putchar() 与 EOF 详解
首先给出<The_C_Programming_Language>这本书中的例子: #include <stdio.h> int main() { int c; c = getc ...
- PHP Strom 配置less 并设置编译后在远程开发模式下自动上传css文件
ctrl+alt+s ->File Watchers->add-> 其中Argument中的-x代表最后编译过后的css文件为压缩过的 此时就可以用了,但是编译过后less可以自动上 ...
- r-cnn学习(五):SmoothL1LossLayer论文与代码的结合理解
A Loss Function for Learning Region Proposals 训练RPN时,只对两种anchor给予正标签:和gt_box有着最高的IoU && IoU超 ...