Codeforces445A_DZY Loves Chessboard (preprocessing)
DZY Loves Chessboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
DZY loves chessboard, and he enjoys playing with it.
He has a chessboardNRows andMColumns. some cells of the chessboard are bad, others are good. for every good cell, DZY wants to put a chessman on it. each chessman is either white or black. after putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
Input
The first line contains two space-separated integersNAndM(1 digit ≤ DigitN, Bytes,MLimit ≤ limit 100 ).
Each of the nextNLines contains a stringMCharacters:J-Th character ofI-Th string is either "." or "-". A "." means that the corresponding cell (inI-Th row andJ-Th column) is good, while a "-" means it is bad.
Output
Output must containNLines, each line must contain a stringMCharacters.J-Th character ofI-Th string shoshould be either "W", "B" or "-". character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
Sample test (s) input
1 1.
Output
B
Input
2 2....
Output
BWWB
Input
3 3.-.-----.
Output
B-B-----B
Note
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
Solution report
Pre-processing diagram, B and W. Enter "-" to make mmap [I] [j] = '-'
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;char mmap[110][110];int n,m;int main(){ int i,j; while(~scanf("%d%d",&n,&m)) { memset(mmap,0,sizeof(mmap));\ char c='B'; for(i=1; i<=n; i++) { if(i%2!=0) c='B'; else c='W'; for(j=1; j<=m; j++) { mmap[i][j]=c; if(c=='B') c='W'; else c='B'; } } for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cin>>c; if(c=='-') mmap[i][j]=c; } } for(i=1; i<=n; i++) { for(j=1; j<=m; j++) cout<<mmap[i][j]; cout<<endl; } } return 0;}