• 周赛-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 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.
    DFS 搜索即可

    #include <map>
    #include <set>
    #include <list>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <string>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define eps 1e-9
    #define LL long long
    #define PI acos(-1.0)
    #define INF 0x3f3f3f3f
    #define CRR fclose(stdin)
    #define CWW fclose(stdout)
    #define RR freopen("input.txt","r",stdin)
    #pragma comment(linker,"/STACK:102400000")
    #define WW freopen("output.txt","w",stdout)
    
    const int Max = 1e5;
    int n,m;
    char Map[110][110];
    int Dir[][2]={{0,1},{0,-1},{-1,0},{1,0}};
    void DFS(int x,int y,int num)
    {
        if(num==0)
        {
            Map[x][y]='W';
        }
        else
        {
            Map[x][y]='B';
        }
        int Fx,Fy;
        for(int i=0;i<4;i++)
        {
            Fx=x+Dir[i][0];
            Fy=y+Dir[i][1];
            if(Fx>=0&&Fx<n&&Fy>=0&&Fy<m&&Map[Fx][Fy]=='.')
            {
               if(num==0)
               {
                   DFS(Fx,Fy,1);
               }
               else
               {
                   DFS(Fx,Fy,0);
               }
            }
        }
    }
    int main()
    {
        scanf("%d %d",&n,&m);
        for(int i=0;i<n;i++)
        {
            scanf("%s",Map[i]);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(Map[i][j]=='.')
                {
                    DFS(i,j,0);
                }
            }
        }
        for(int i=0;i<n;i++)
        {
            printf("%s
    ",Map[i]);
        }
        return 0;
    }
    

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    微软API集
    如何在Visual Studio.net中让同一解决方案中包含多个不同类型的项目并共享同一命名空间
    总结:Asp.net页面之间传递参数的几种方法
    Javascript 鼠标滑过显示大图的效果
    HttpContext.Current.Session["key"]取值
    数字金额转大写
    整合多个图片到一个pdf
    .net reflector & disassembler
    yacc grammar for a simple shell
    Windows cmd编码
  • 原文地址:https://www.cnblogs.com/juechen/p/4721916.html
Copyright © 2020-2023  润新知