SCAU2020春季个人排位赛div2 #2---F

简单说下

这道题目的大致意思是B和B,W和W不能相邻且“-”代表障碍“*”代表可以放棋子。题目让我们输出放完棋子后的棋盘。
其实这道题没有大家想的这么难,对于一幅图我是记得很清楚的,不知道大家是怎么样,这幅图在《算法竞赛入门经典第二版》里面,就是坐标x和坐标y相加和相减后对应的数值图,应该在八皇后的那题附近把。x+y所得的数值图里面,白色的格子和黑色的格子中有一个格子是可以被2整除的,而且黑色和黑色,白色和白色的格子不会连续,刚好符合如上情况,所以我们可以假设这个棋盘一开始就决定每个位置上放什么棋子了,剩下的只是去掉障碍对应的格子而已。

题目如下

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.
Examples
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<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<deque>
using namespace std;
#define ll long long
char map1[110][110];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            {
                cin>>map1[i][j];
                if(map1[i][j]!='-')
                {
                    if((i+j)&1)
                        map1[i][j]='W';
                        else map1[i][j]='B';
                }
            }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
                cout<<map1[i][j];
        cout<<endl;
    }
    return 0;
}

发布了43 篇原创文章 · 获赞 26 · 访问量 3084

猜你喜欢

转载自blog.csdn.net/Leo_zehualuo/article/details/104462638
今日推荐