zoukankan      html  css  js  c++  java
  • 周赛-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;
    }
    

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

  • 相关阅读:
    1,300萬像素Xperia TX K.O.相機 東方日報
    信息检索Reading List
    雷军:小米二为何不用1300万像素相机_TechWeb
    1300万像素高清双核旗舰 索尼LT30p评测_手机_科技时代_新浪网
    Darts: DoubleARray Trie System海 的 声音我的搜狐
    说说底层架构之实体类的设计
    不忘本~枚举
    两种底层数据层操作时的架构方式,你喜欢那种?
    说说C#中的global
    JS对外部文件的加载及对IFRMAME的加载的实现,当加载完成后,指定指向方法(方法回调)
  • 原文地址:https://www.cnblogs.com/juechen/p/4721916.html
Copyright © 2011-2022 走看看