转载请注明出处: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.

Input

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

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.

Sample test(s)
input
1 1
.
output
B
input
2 2
..
..
output
BW
WB
input
3 3
.-.
---
--.
output
B-B
---
--B
Note

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(纯实现题)的更多相关文章

  1. CodeForces445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  2. DZY Loves Chessboard

    DescriptionDZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m ...

  3. CodeForces - 445A - DZY Loves Chessboard

    先上题目: A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input ...

  4. 周赛-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 ...

  5. cf445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. 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 ...

  7. CF 445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  8. CF 445A(DZY Loves Chessboard-BW填充)

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard —— dfs

    题目链接: http://codeforces.com/problemset/problem/445/A 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...

随机推荐

  1. 【贪心优化dp决策】bzoj1571: [Usaco2009 Open]滑雪课Ski

    还有贪心优化dp决策的操作…… Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里 ...

  2. [CODEVS] 3955 最长严格上升子序列(加强版)

    题目描述 Description 给一个数组a1, a2 ... an,找到最长的上升降子序列ab1<ab2< .. <abk,其中b1<b2<..bk. 输出长度即可. ...

  3. Vue的响应式规则

    对象属性的响应规则 <body> <div id="root"> {{msg}} </div> </body> <script ...

  4. CSS3-媒体类型

    一.媒体类型(Media Type) 1.link方法引入 <link rel="stylesheet" type="text/css" href=&qu ...

  5. (转)自定义UITabBar

    push页面时,可调用hidesBottomBarWhenPushed进行隐藏. 第一步,我们需要一些图片: 各个选项的图标和tabbar的背景图片,最后还要一个透明的1x1像素的图片. 第二步,新建 ...

  6. 【笔记】PIL 中的 Image 模块

    Image 模块提供了一个同名类(Image),也提供了一些工厂函数,包括从文件中载入图片和创建新图片.例如,以下的脚本先载入一幅图片,将它旋转 45 度角,并显示出来: 1 >>> ...

  7. LeetCode(113) Path Sum II

    题目 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given ...

  8. 【LeetCode】Symmetric Tree(对称二叉树)

    这道题是LeetCode里的第101道题.是我在学数据结构——二叉树的时候碰见的题. 题目如下: 给定一个二叉树,检查它是否是镜像对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 ...

  9. PAT Basic 1044

    1044 火星数字 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly ...

  10. PAT Basic 1010

    1010 一元多项式求导 设计函数求一元多项式的导数.(注:x^n^(n为整数)的一阶导数为n*x^n-1^.) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数). ...