(CF)Codeforces445A DZY Loves Chessboard(纯实现题)
转载请注明出处:http://blog.csdn.net/u012860063?
viewmode=contents
题目链接:http://codeforces.com/problemset/problem/445/A
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 <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int i, j;
int n, m;
char map[117][117],G[117][117];
while(scanf("%d%d",&n,&m)!=EOF)
{
getchar();
for(i = 0; i < n; i++)
{
scanf("%s",map[i]);
}
for( i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
if(map[i][j] == '-')
G[i][j] = '-';
else if(i %2 == 0)
{
if(j%2 == 0)
{
G[i][j] = 'B';
}
else
G[i][j] = 'W';
}
else if(i%2 == 1)
{
if(j%2 == 1)
{
G[i][j] = 'B';
}
else
G[i][j] = 'W';
}
}
}
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
printf("%c",G[i][j]);
}
printf("\n");
}
}
return 0;
}
(CF)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
		
DescriptionDZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m ...
 - CodeForces - 445A - DZY Loves Chessboard
		
先上题目: A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input ...
 - 周赛-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 ...
 - 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 ...
 - CF 445A(DZY Loves Chessboard-BW填充)
		
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 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...
 
随机推荐
- PAT 乙级 1041
			
题目 题目地址:PAT 乙级 1041 题解 这道题学到的东西恰好和1037中学到的东西相互补充,总结如下: 在之前的博文中我曾提到过——“结构体在函数内部对数据的操作不能赋给主函数中的实参,函数内部 ...
 - 【Linux命令大全】
			
Linux常用命令大全 系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部 ...
 - logstash-基础操作
			
一.环境 https://www.cnblogs.com/suffergtf/p/9566145.html 1.收取日志文件到elasticsearch [root@linux-node1 logst ...
 - windows终端输入pip install requests报错:Fatal error in launcher
			
emm今天群友发了个图,说他的pip报错,是这个问题 emmm这个问题我也不太懂,后来让他pip install requests这样操作,, 还是不管用,我寻思这个错咋回事,让他用 python ...
 - python--第一类对象,函数名,变量名
			
一 . 第一类对象 函数对象可以像变量一样进行赋值 , 还可以作为列表的元素进行使用 可以作为返回值返回 , 可以作为参数进行传递 def func(): def people(): print('金 ...
 - python学习第一天 计算机基础知识
			
目录 什么是编程语言 什么是编程? 为什么要编程? 计算机5大组成分别有什么作用? qq启动的流程? 建议相关学习 课外 什么是编程语言 什么是编程语言? python和中文.英语一样,都是一门语言, ...
 - MIP启发式求解:局部搜索 (local search)
			
*本文主要记录和分享学习到的知识,算不上原创. *参考文献见链接. 本文讲述的是求解MIP问题的启发式算法. 启发式算法的目的在于短时间内获得较优解. 个人认为局部搜索(local search)几乎 ...
 - 4C. Stars
			
4C. Stars Time Limit: 2000ms Case Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO forma ...
 - nginx报错504
			
Nginx 504错误(Gateway time-out 网关超时)的含义是所请求的网关没有请求到,简单来说就是没有请求到可以执行的PHP-CGI. 一般看来, 这种情况可能是由于nginx默认的f ...
 - web.xml不同的头文件
			
<转自:http://blog.csdn.net/qq_16313365/article/details/53783288> 1. Servlet 3.1 Java EE 7 XML sc ...