zoukankan      html  css  js  c++  java
  • Codeforces Round #632 (Div. 2) A. Little Artem(水题)

    Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help.

    Artem wants to paint an n×mn×m board. Each cell of the board should be colored in white or black.

    Lets BB be the number of black cells that have at least one white neighbor adjacent by the side. Let WW be the number of white cells that have at least one black neighbor adjacent by the side. A coloring is called good if B=W+1B=W+1.

    The first coloring shown below has B=5B=5 and W=4W=4 (all cells have at least one neighbor with the opposite color). However, the second coloring is not good as it has B=4B=4, W=4W=4 (only the bottom right cell doesn't have a neighbor with the opposite color).

    Please, help Medina to find any good coloring. It's guaranteed that under given constraints the solution always exists. If there are several solutions, output any of them.

    Input

    Each test contains multiple test cases.

    The first line contains the number of test cases tt (1t201≤t≤20). Each of the next tt lines contains two integers n,mn,m (2n,m1002≤n,m≤100) — the number of rows and the number of columns in the grid.

    Output

    For each test case print nn lines, each of length mm, where ii-th line is the ii-th row of your colored matrix (cell labeled with 'B' means that the cell is black, and 'W' means white). Do not use quotes.

    It's guaranteed that under given constraints the solution always exists.

    Example
    Input
    Copy
    2
    3 2
    3 3
    
    Output
    Copy
     
    BW
    WB
    BB
    BWB
    BWW
    BWB

    我是傻逼
    读错题了==还以为B和W是总的数目且要求B=W+1...狂写一通感慨A题怎么这么难然后发现样例WTF....

    注意这个题的B和W是与另一个颜色格子相邻的格子数目!如果不相邻的话是不会被统计在里面的。直接构造左上角是W其他是B即可。
    #include <bits/stdc++.h>
    using namespace std;
    int t,m,n;
    int main()
    {
        cin>>t;
        while(t--)
        {
            cin>>n>>m;
            int i,j;
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                {
                    if(i==1&&j==1)cout<<'W';
                    else cout<<'B';
                }
                cout<<endl;
            }
        }
        return 0;
    }


  • 相关阅读:
    线段树(单点更新) HDOJ 2795 Billboard
    线段树(单点更新) HDU 1754 I Hate It
    线段树(单点更新)/树状数组 HDOJ 1166 敌兵布阵
    递推DP URAL 1031 Railway Tickets
    记忆化搜索(DFS+DP) URAL 1223 Chernobyl’ Eagle on a Roof
    递推DP URAL 1244 Gentlemen
    DFS水题 URAL 1152 False Mirrors
    记忆化搜索(DFS+DP) URAL 1501 Sense of Beauty
    DP+高精度 URAL 1036 Lucky Tickets
    DP/最短路 URAL 1741 Communication Fiend
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12665813.html
Copyright © 2011-2022 走看看