Codeforces 1221B. Knights

传送门

看到棋盘上跳马,发现如果把棋盘黑白染色,那么每次移动都是从白点到黑点,从黑点到白点

所以直接根据黑白染色判断每个位置的马的颜色即可

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
const int N=1007;
int n;
int main()
{
    n=read();
    for(int i=1;i<=n;i++,puts(""))
        for(int j=1;j<=n;j++)
            if((i+j)&1) printf("W");
            else printf("B");
    return 0;
}
原文地址:https://www.cnblogs.com/LLTYYC/p/11556465.html