Interesting questions. It is very easy to think of, and it is troublesome to think of it.
It is actually a reverse thinking: the final result must be like this:
Wbwbwbwb...
Bwbwbwbw...
Wbwbwbwb...
...
Change "-".
But I started to think about how to handle each vertex. It also depends on the status of the vertex around it. The more I think about it, the more troublesome it is...
The positive and difficult reverse thinking embodied in this question is worth learning.
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<map>#include<set>#include<vector>#include<algorithm>#include<stack>#include<queue>using namespace std;#define INF 1000000000#define eps 1e-8#define pii pair<int,int>#define LL long long intint n,m;char mp[105][105];int main(){ //freopen("in1.txt","r",stdin); //freopen("out.txt","w",stdout); scanf("%d%d",&n,&m); getchar(); for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { scanf("%c",&mp[i][j]); } getchar(); } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(mp[i][j]==‘-‘) { printf("-"); } else { if((i+j)&1) { printf("B"); } else printf("W"); } } printf("\n"); } //fclose(stdin); //fclose(stdout); return 0;}