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:
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 output Copy Note In the first example, there are 88 duels:
|
【补充】(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;
}