B. Knights

滴答滴答---题目链接 

B. Knights

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a chess board with nn rows and nn columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.

A knight is a chess piece that can attack a piece in cell (x2x2, y2y2) from the cell (x1x1, y1y1) if one of the following conditions is met:

  • |x1−x2|=2|x1−x2|=2 and |y1−y2|=1|y1−y2|=1, or
  • |x1−x2|=1|x1−x2|=1 and |y1−y2|=2|y1−y2|=2.

Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).

A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.

Input

The first line contains one integer nn (3≤n≤1003≤n≤100) — the number of rows (and columns) in the board.

Output

Print nn lines with nn characters in each line. The jj-th character in the ii-th line should be W, if the cell (ii, jj) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.

Example

input

Copy

3

output

Copy

WBW
BBB
WBW

Note

In the first example, there are 88 duels:

  1. the white knight in (11, 11) attacks the black knight in (33, 22);
  2. the white knight in (11, 11) attacks the black knight in (22, 33);
  3. the white knight in (11, 33) attacks the black knight in (33, 22);
  4. the white knight in (11, 33) attacks the black knight in (22, 11);
  5. the white knight in (33, 11) attacks the black knight in (11, 22);
  6. the white knight in (33, 11) attacks the black knight in (22, 33);
  7. the white knight in (33, 33) attacks the black knight in (11, 22);
  8. the white knight in (33, 33) attacks the black knight in (22, 11).

【补充】(i&1) 是按位 与 运算,相当于 取出 i 的2 进制数值的个位数。 如果 i 是 十进制 奇数,i&1 得 1; 如果 i 是 十进制 偶数,i&1 得 0。 

题意:

要在一个n*n的棋盘中放满黑和白方的马, 马走日, 求出最优方案使得双方所有马的攻击次数最多

 

#include <iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if((i+j)&1)
                cout<<"B";
            else cout<<"W";
        }
        cout<<endl;
    }
    return 0;
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值