https://codeforces.com/problemset/problem/1221/B
很显然的结论,黑白相间就肯定最多
然而我这个菜鸡写的dfs卧槽,菜不成声.jpg
这个是2分钟别人写完的
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin>>n;
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
if((i+j)%2==0){
cout<<"W";
}else{
cout<<"B";
}
}
cout<<endl;
}
return 0;
}
这个我写了9分钟,我太菜了
#include<bits/stdc++.h>
#define maxl 110
using namespace std;
int n,m,ans;
int a[maxl][maxl];
bool vis[maxl][maxl];
char s[maxl];
int tx[9]={0,1,1,2,2,-1,-1,-2,-2};
int ty[9]={0,2,-2,1,-1,2,-2,1,-1};
inline void prework()
{
scanf("%d",&n);
}
inline void dfs(int x,int y,int d)
{
a[x][y]=d;vis[x][y]=true;
int xx,yy;
for(int i=1;i<=8;i++)
{
xx=x+tx[i];yy=y+ty[i];
if(xx<1 || xx>n || yy<1 || yy>n)
continue;
if(vis[xx][yy])
continue;
dfs(xx,yy,3-d);
}
}
inline void mainwork()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(!vis[i][j])
dfs(i,j,1);
}
inline void print()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
if(a[i][j]==1)
putchar('W');
else
putchar('B');
puts("");
}
}
int main()
{
int t=1;
//scanf("%d",&t);
for(int i=1;i<=t;i++)
{
prework();
mainwork();
print();
}
return 0;
}