304977: CF948A. Protect Sheep
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Protect Sheep
题意翻译
## 题目背景:(有少许简化和修改,但依然符合题意) Bob是个农夫,他有一个$R*C$ 的草地。 草地上有许多羊,同时也有许多狼。 羊不会动,但是狼会向上下左右四个方向动。 所以Bob打算在草地上放上狗,使狼和羊完全隔开。 你的任务就是输出一种可行方案, 放的狗的数量不必最少。 ## 输入格式: 第一行两个数$R$ $(1<=R<=500)$ 和$C$ $(1<=C<=500)$ 接下来$R$ 行,每行一个长度为C的字符串。来表示这片草地上的东西。 其中'.'是空地,'W'是狼,'S'是羊。 ## 输出格式: 第一行输出$Yes$或$No$,表示是否可行。 如果可行$Yes$ 接下来输出$R$行,每行一个长度为$C$的字符串。 来表示放完狗之后的情况。 狗只能放到空地上,用'D'表示。 感谢@cn:苏卿念 提供的翻译题目描述
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.输入输出格式
输入格式
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.
输出格式
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.
输入输出样例
输入样例 #1
6 6
..S...
..S.W.
.S....
..W...
...W..
......
输出样例 #1
Yes
..SD..
..SDW.
.SD...
.DW...
DD.W..
......
输入样例 #2
1 2
SW
输出样例 #2
No
输入样例 #3
5 5
.S...
...S.
S....
...S.
.S...
输出样例 #3
Yes
.S...
...S.
S.D..
...S.
.S...