zoukankan      html  css  js  c++  java
  • 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;
      }
    }
    View Code
  • 相关阅读:
    Linux XOR.DDoS样本取证特征与清除
    利用Volatility对Linux内存取证分析-常用命令翻译
    【黑客免杀攻防】读书笔记14
    CertUtil.exe被利用来下载恶意软件
    利用rundll32执行程序的函数执行程序
    揭秘Patchwork APT攻击-恶意软件样本BADNEWS
    【CTF MISC】pyc文件反编译到Python源码-2017世安杯CTF writeup详解
    [ 总结 ] 删除通过find查找到的文件
    [ 脚本 ] RHEL6.x 及Centos6.x 初始化脚本
    [ 手记 ] 联想rd650服务器整列及系统安装
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6873421.html
Copyright © 2011-2022 走看看