Codeforces 445A. DZY Loves Chessboard

DZY loves chessboard, and he enjoys playing with it.

He has a chessboard of n rows and m columns. 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 integers n and m (1?≤?n,?m?≤?100).

Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.

Output

Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should 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.

光考虑dfs去了石乐志。其实就是按对角线摆放即可,被bad cell迷惑到了

#include <cstdio>
#include <cctype>
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <map>

using namespace std;
typedef long long LL;

char board[105][105];
int n,m;
int main()
{
  // freopen("test.in","r",stdin);
  cin >> n >> m;
  memset(board,0,sizeof(board));
  for (int i=1;i<=n;i++){
    char s[105];
    cin >> s;
    for (int j=1;j<=m;j++){
      board[i][j] = s[j-1];
      if (board[i][j] != ‘-‘){
        if ((i+j) & 1){
          board[i][j] = ‘B‘;
        }
        else {
          board[i][j] = ‘W‘;
        }
      }
    }
  }
  for (int i=1;i<=n;i++){
    for (int j=1;j<=m;j++){
      cout << board[i][j];
    }
    cout << endl;
  }
}

时间: 2024-10-13 10:04:28

Codeforces 445A. DZY Loves Chessboard的相关文章

CodeForces - 445A - DZY Loves Chessboard解题报告

对于这题本人刚开始的时候觉得应该用DFS来解决实现这个问题,但由于本人对于DFS并不是太熟,所以就放弃了这个想法: 但又想了想要按照这个要求实现问题则必须是黑白相间,然后把是字符是'B'或'W'改为'-',即可: 下面贴一下我的代码吧 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define N 100+10 5 using namespace std; 6 7 char maze[N]

(CF)Codeforces445A DZY Loves Chessboard(纯实现题)

转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://codeforces.com/problemset/problem/445/A DZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, oth

Codeforces 444A DZY Loves Physics(图论)

题目链接:Codeforces 444A DZY Loves Physics 题目大意:给出一张图,图中的每个节点,每条边都有一个权值,现在有从中挑出一张子图,要求子图联通,并且被选中的任意两点,如果存在边,则一定要被选中.问说点的权值和/边的权值和最大是多少. 解题思路:是图论中的一个结论,最多两个节点,所以枚举两条边就可以了.我简单的推了一下,2个点的情况肯定比3个点的优. 假设有3个点a,b,c,权值分别为A,B,C 现a-b,b-c边的权值分别为u,v 那么对于两点的情况有A+Bu,B+

Codeforces 444B DZY Loves FFT(概率)

题目连接:Codeforces 444B DZY Loves FFT 题目大意:根据题目的算法生成a,b数组,然后对于每个长度的l,求a[i]*b[l-i]的最大值. 解题思路:概率问题,枚举前30大的数,如果有就可以直接输出答案,如果没有,就暴力枚举b数组为1的位置找最大值. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long

codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2). DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ...,

Codeforces 444C DZY Loves Colors(线段树)

题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是修改区间上l到r上面德值为x,2是询问l到r区间总的修改值. 解题思路:线段树模板题. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; const int maxn = 5*1e5; typedef long lo

codeforces 446C DZY Loves Fibonacci Numbers 数论+线段树成段更新

DZY Loves Fibonacci Numbers Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Appoint description:  System Crawler  (2014-07-14) Description In mathematical terms, the sequence Fn of Fibonacci numbers is defi

Codeforces 445B DZY Loves Chemistry(并查集)

题目链接:Codeforces 445B DZY Loves Chemistry 题目大意:有若干种化学药品,给出两两会反应的关系,现在要将药物依次放入一个容器中,容器中的化学药品可以互相反应,如果当前放入的药品能与已经在容器中的某一药品反应,那么危险值翻倍,即*2,初始值为1,求一顺序,使得为危险值最大. 解题思路:并查集求最小联通分量s,2n?s即为答案. #include <cstdio> #include <cstring> #include <iostream>

Codeforces 446B DZY Loves Modification 矩阵行列分开考虑 优先队列+构造

题目链接:点击打开链接 题意: 给定n行m列的矩阵 k次操作,一个常数p ans = 0; 对于每次操作 可以任选一行或一列, 则ans += 这行(列)的数字和 然后这行(列)上的每个数字都-=p 问最大的ans 思路: 首先我们设最终选了 行 i 次,则列选了 k-i 次 那么假设我们先全部选行,然后选列,则每次选列时,要-= i*p 这样最后是 -= i*(k-i)*p 也就是所有行对列的影响 那我们先把这个 i*(k-i)*p 提出来,那么选行和选列就互不影响 就可以分别考虑行和列 对于