• CF A Little Artem(4月8日)


    Little Artem
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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+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
    2
    3 2
    3 3
    
    output
    BW
    WB
    BB
    BWB
    BWW
    BWB
    Note

    In the first testcase, B=3B=3, W=2W=2.

    In the second testcase, B=5B=5, W=4W=4. You can see the coloring in the statement.

    题意:就保证有  相邻白色格子 和黑色格子 比有相邻 白色格子 的 黑色格子 多一(听起来有点绕口的说)

    画个图理解

    B

    B

    B

    W

    B

    B

    B

    W

    B

    B

    B

    W

    B

    B

    B

    B

    (完美)

    上代码

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4         int t;
     5         cin>>t;
     6  while(t--){
     7      int m,n;
     8      cin>>m>>n;
     9      for(int i=1;i<m;i++){
    10          for(int j=1;j<n;j++){
    11              cout<<"B";
    12          }
    13          cout<<"W"<<'
    ';
    14      }
    15      for(int i=0;i<n;i++){
    16          cout<<"B";
    17      }cout<<'
    ';
    18  }
    19 
    20 return 0;
    21 }

     

  • 相关阅读:
    php 高级 提高PHP代码的性能10条建议
    CSRF预防手段
    如何在PHP中防止SQL注入
    网络安全 如何防范 XSS 攻击
    php 算法知识 冒泡排序
    php 基础知识 常见面试题
    MySQL高级 InnoDB 和 MyISAM 的区别
    php 算法知识 猴子选大王
    MySQL高级-索引1
    [POI2007]POW-The Flood(并查集)
  • 原文地址:https://www.cnblogs.com/ahijing/p/12678508.html
Copyright © 2020-2023  润新知