周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏
DZY Loves Chessboard
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Sample test(s)
Input
1 1
.
Output
B
Input
2 2
..
..
Output
BW
WB
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.
DFS 搜索即可
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define CRR fclose(stdin)
#define CWW fclose(stdout)
#define RR freopen("input.txt","r",stdin)
#pragma comment(linker,"/STACK:102400000")
#define WW freopen("output.txt","w",stdout)
const int Max = 1e5;
int n,m;
char Map[110][110];
int Dir[][2]={{0,1},{0,-1},{-1,0},{1,0}};
void DFS(int x,int y,int num)
{
if(num==0)
{
Map[x][y]='W';
}
else
{
Map[x][y]='B';
}
int Fx,Fy;
for(int i=0;i<4;i++)
{
Fx=x+Dir[i][0];
Fy=y+Dir[i][1];
if(Fx>=0&&Fx<n&&Fy>=0&&Fy<m&&Map[Fx][Fy]=='.')
{
if(num==0)
{
DFS(Fx,Fy,1);
}
else
{
DFS(Fx,Fy,0);
}
}
}
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%s",Map[i]);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(Map[i][j]=='.')
{
DFS(i,j,0);
}
}
}
for(int i=0;i<n;i++)
{
printf("%s\n",Map[i]);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏的更多相关文章
- 1.PHP站内搜索 分类: PHP开发实例 2015-07-31 22:48 4人阅读 评论(0) 收藏
PHP站内搜索:多关键字.加亮显示 1.SQL语句中的模糊查找 $sql = "SELECT * FROM `message` WHERE `content`like '%$k[0]%' a ...
- 搜索 基础 AC 2014-01-14 15:53 170人阅读 评论(0) 收藏
题目网址:http://haut.openjudge.cn/xiyoulianxi1/1/ 1:晶矿的个数 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 ...
- XHTML 结构化:使用 XHTML 重构网站 分类: C1_HTML/JS/JQUERY 2014-07-31 15:58 249人阅读 评论(0) 收藏
http://www.w3school.com.cn/xhtml/xhtml_structural_01.asp 我们曾经为本节撰写的标题是:"XHTML : 简单的规则,容易的方针.&qu ...
- 修改android应用包名 分类: android 学习笔记 2015-07-16 22:48 4人阅读 评论(0) 收藏
由于项目需要,要修改已经开发好的应用包名,这本身很简单,但是如果你没找到门道,可能会白白浪费许多时间. 修改包名有三个地方要改,这三个地方的修改一定要按顺序来,否则你可能会遇到许多不必要的麻烦. 1. ...
- 线程间的参数传递 分类: linux c/c++ 2014-06-15 17:48 607人阅读 评论(0) 收藏
在多线程编程中,常常需要从主线程传递参数给子线程或在主线程中获得子线程的计算结果, 若使用全局变量实现,必然需要对临界区保护,因此导致大量的切换工作造成效率的低下: 而利用进程间的参数传递可以解决这一 ...
- 8大排序算法图文讲解 分类: B10_计算机基础 2014-08-18 15:36 243人阅读 评论(0) 收藏
排序算法可以分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 常见的内部排序算法有:插入排序.希尔排序. ...
- javascript中0级DOM和2级DOM事件模型浅析 分类: C1_HTML/JS/JQUERY 2014-08-06 15:22 253人阅读 评论(0) 收藏
Javascript程序使用的是事件驱动的设计模式,为一个元素添加事件监听函数,当这个元素的相应事件被触发那么其添加的事件监听函数就被调用: <input type="button&q ...
- DZY Loves Chemistry 分类: CF 比赛 图论 2015-08-08 15:51 3人阅读 评论(0) 收藏
DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 周赛-Equidistant String 分类: 比赛 2015-08-08 15:44 6人阅读 评论(0) 收藏
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
随机推荐
- Java NIO 开篇
一些很好的blog(待更新): 1.NIO入门 2.NIO.2 入门,第 1 部分: 异步通道 API I- 就是从硬盘到内存 O- 就是从内存到硬盘 一.阻塞IO 第一种方式:我从硬盘读取数据,然后 ...
- 来自“Java中国”优秀的程序员不会觉得累成狗是一种荣耀
分享下“https://java-china.org/topic/28“,也算是对自己的一种告诫吧. 原文:Sleep deprivation is not a badge of honor 先介绍一 ...
- JAVA-面向对象-继承
继承 (关键字extends ) (关键字 final 表示终态,在父类前加 final 则父类无法被继承,加在方法前则方法不能被重写或者覆盖,加在变量前则变量只能被赋值一次) 1.权限修饰符 ...
- [原创]java WEB学习笔记55:Struts2学习之路---详解struts2 中 Action,如何访问web 资源,解耦方式(使用 ActionContext,实现 XxxAware 接口),耦合方式(通过ServletActionContext,通过实现 ServletRequestAware, ServletContextAware 等接口的方式)
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- VS2010程序打包
今天,小白就来给各位做个打包的新手教程,此文仅是为了记录自己的学习过程与方便其他初次接触的打包的朋友们总结一下,希望大家能够受用.废话不多说,下面我们就来讲解下打包工程.首先,在项目中添加一个安装项目 ...
- 封装mysqli类
类: <?phpheader('content-type:text/html;charset=utf-8');/*掌握满足单例模式的必要条件(1)私有的构造方法-为了防止在类外使用new关键字实 ...
- angular filter
日期格式化: <span ng-bind="topShowList.sendTime|dateFormat|date:'MM-dd HH:mm'"></span& ...
- 13.熟悉JDK的配置,环境变量
已经做烂的东西,公司的新人环境配置手册文档Java方面的就是我写的,有意的留邮箱,很详细
- Mysql触发器总结
触发器(trigger):监视某种情况,并触发某种操作. 触发器创建语法四要素:1.监视地点(table) 2.监视事件(insert/update/delete) 3.触发时间(after/befo ...
- Vim篇
Vim编辑器中的一些常用命令: 1:shift+* , 选取光标所在处的整个字符,并查找.(十分方便),快捷键gd 2:set nu , 显示各行行号,使得基于行的命令更方便. 3:shift+% , ...