Codeforces Round #254 (Div. 二) A. DZY Loves Chessboard

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
standard input
output
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.

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.

判定条件为(i+j)%2=0并且a [ i ] =‘ . ’   则放B或者W(随意选优先哪个字母)

#include<bits/stdc++.h>
#define maxn 105
using namespace std;
int main()
{
    int m,n,i,j;
    char a[maxn][maxn];
    cin>>n>>m;
        for(i=0;i<n;i++)
            cin>>a[i];
        for(i=0;i<n;i++)
           {
               for(j=0;j<m;j++)
               {
                   if(a[i][j]!='-')
                    {
                       if((i+j)%2==0)
                           a[i][j]='B';
                       else
                           a[i][j]='W';
                    }
                    cout<<a[i][j];
               }
               cout<<endl;
           }

    return 0;
}


3楼u0100927345小时前
[code=cpp]n#include<stdio.h>n#include<string.h>nint n, m;nchar hei = 'B';nchar bai = 'W';nchar map[120][120] = {0};nint x_place[4] = {0,0,-1,1};nint y_place[4] = {1,-1,0,0};nint check(int x , int y)n{ntint tx = 0;ntint ty = 0;ntfor(int i = 0; i < 4; i++)nt{ntttx = x + x_place[i];nttty = y + y_place[i];nnttif((tx < 0 || tx >=n) || (y < 0 || y >=m))ntttcontinue;nttif(map[tx][ty] == 'W')ntttreturn 0;nttelse if(map[tx][ty] == 'B')ntttreturn 1;nt}ntreturn 0;n}nvoid put(int q, int w)n{ntint flag = 0;ntflag = check(q,w);ntif(flag) map[q][w] = 'W';ntelse map[q][w] = 'B';n}nvoid DFS(int s, int e)n{ntput(s, e);ntint tempx = 0;ntint tempy = 0;ntfor(int i = 0; i < 4; i++)nt{ntttempx = s + x_place[i];ntttempy = e + y_place[i];nnttif((tempx < 0 || tempx >=n) || (tempy < 0 || tempy >=m))ntttcontinue;nttif(map[tempx][tempy] == '.')ntt{ntttDFS(tempx, tempy);ntt}nt}n}n[/code]
2楼u010092734昨天 17:02
int main()n{nt//freopen("G:\\in.txt", "r", stdin);ntint x1, y1;ntint flag = 0;ntwhile(scanf("%d%d", &n, &m) !=EOF)nt{ntt//getchar();nttmemset(map, 0, sizeof(map));nttfor(int i = 0; i < n; i++)ntt{nntttscanf("%s",&map[i]);nttt//getchar();ntt}nttfor(int i = 0; i < n; i++)ntt{ntttfor(int j = 0; j < m; j++)nttt{nttttif(map[i][j] != '-' && map[i][j] != 'W' && map[i][j] != 'B')ntttt{nntttttDFS(i,j);ntttt}nttt}ntt}nttfor(int i = 0; i < n; i++)ntttprintf("%s\n", map[i]);nt}ntreturn 0;n}
Re: u014689045昨天 17:06
回复u010092734n???
Re: u013487051昨天 20:37
回复u014689045n人家用的DFS写的。。
Re: u0146890455小时前
回复u013487051n我知道...
1楼u014791736昨天 15:09
博主写了e的题解可好