http://codeforces.com/contest/948/problem/A

 
A. Protect Sheep

Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.

The pasture is a rectangle consisting of R × C cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.

Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number.

Input

First line contains two integers R (1 ≤ R ≤ 500) and C (1 ≤ C ≤ 500), denoting the number of rows and the numbers of columns respectively.

Each of the following R lines is a string consisting of exactly C characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell.

Output

If it is impossible to protect all sheep, output a single line with the word "No".

Otherwise, output a line with the word "Yes". Then print R lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.

If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs.

Examples
input

Copy
6 6
..S...
..S.W.
.S....
..W...
...W..
......
output
Yes
..SD..
..SDW.
.SD...
.DW...
DD.W..
......
input

Copy
1 2
SW
output
No
input

Copy
5 5
.S...
...S.
S....
...S.
.S...
output
Yes
.S...
...S.
S.D..
...S.
.S...
Note

In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.

In the second example, there are no empty spots to put dogs that would guard the lone sheep.

In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him.

题意就是给一个N*C矩阵,让你往空白的'.'的地方放狗,用来把羊'S'和狼'W'分隔开来,狗的数量不限,输出任意解。所以只要遍历整个矩阵,如果有S和W相邻则不可行,反之可行,所有空白处都放上狗。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define eps 0.00000001
#define pn printf("\n")
using namespace std;
typedef long long ll; int n,m;
char s[][];
int to[][] = {,,,-,,,-,}; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
scanf("%s",s[i]);
int fl = ;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
if(s[i][j] == 'S')
{
for(int k=;k<;k++)
{
int tx = i + to[k][], ty = j + to[k][];
if(tx >= && tx < n && ty >= && ty < m)
{
if(s[tx][ty] == 'W')
{
fl = ; break;
}
}
}
}
}
if(fl) printf("No\n");
else
{
printf("Yes\n");
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(s[i][j] == '.') printf("D");
else printf("%c",s[i][j]);
}
printf("\n");
}
}
}

Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)A. Protect Sheep的更多相关文章

  1. Codeforces Round #470 (rated, Div. 1, based on VK Cup 2018 Round 1) 923D 947D 948E D. Picking Strings

    题: OvO http://codeforces.com/contest/947/problem/D 923D 947D 948E 解: 记要改变的串为 P1 ,记目标串为 P2  由变化规则可得: ...

  2. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow

    题目链接  题意  每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...

  3. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)

    A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)B. Primal Sport

    Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try ...

  5. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) F 构造

    http://codeforces.com/contest/967/problem/F 题目大意: 有n个点,n*(n-1)/2条边的无向图,其中有m条路目前开启(即能走),剩下的都是关闭状态 定义: ...

  6. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) E 贪心

    http://codeforces.com/contest/967/problem/E 题目大意: 给你一个数组a,a的长度为n 定义:b(i) = a(1)^a(2)^......^a(i), 问, ...

  7. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D 贪心

    http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x ...

  8. 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

    题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...

  9. 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio

    题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...

随机推荐

  1. `itchat`配置代理

    config.py配置 首先,先找到itchat安装的目录,然后定位到config.py文件: import os, platform VERSION = '1.3.10' BASE_URL = 'h ...

  2. MySQL笔记5-----索引(覆盖索引等)

    1.概念: 覆盖索引:(个人理解)就是包含所有查询记录的索引.当查询量过大时可以采用覆盖索引来进行查询,效率较高. 回表:建立覆盖索引就是避免回表,回表效率会很慢. select查询的字段只有索引列, ...

  3. Django_学生管理系统

    一. Django简易学生管理系统 1.在pycharm中创建工程student_manage_system,添加app:student_manage 2.配置静态文件:在工程项目目录下新建目录sta ...

  4. sublime 自定义快捷生成代码块

    菜单栏目选 Tools(工具) =>Developer(插件开发)=>New Snippet....(新建代码片段),如图: 接着会新开一个标签页,会附带一些内容:如图: 将“Hello, ...

  5. Spring 使用外部属性文件配置

    1.Spring提供了一个PropertyPlaceholderConfigurer的BeanFactory后置处理器,这个处理器允许用户将Bean的配置的部分内容 移到属性文件中.可以在Bean配置 ...

  6. ubuntu上的arm-elf-tools -20040427.sh 下载及安装问题的解决

    要完成uclinux在ARM上的移植,必须有这个工具. 下载地址:http://opensrc.sec.samsung.com/download.html 这个网站上还有许多其它资源可以下载.我选择 ...

  7. 【codeforces 723F】st-Spanning Tree

    [题目链接]:http://codeforces.com/contest/723/problem/F [题意] 给你一张图; 让你选择n-1条边; 使得这张图成为一颗树(生成树); 同时s的度数不超过 ...

  8. 深入MNIST code测试

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50624471 依照教程:深入MNIST ...

  9. ScrollView+RadioGroup

    今天要分享一下关于动态添加RadioButton的东西: 要实现的效果就是,这个控件可以左右滑动,里面的按钮都是互斥的,类似RadioButton,我的第一反应就是用ScrollView+RadioG ...

  10. [Android中级]使用Commons-net-ftp来实现FTP上传、下载的功能

    本文属于学习分享,如有雷同纯属巧合 利用业余时间.学习一些实用的东西,假设手又有点贱的话.最好还是自己也跟着敲起来. 在android上能够通过自带的ftp组件来完毕各种功能.这次是由于项目中看到用了 ...