CF948A Protect Sheep

    • 184通过
    • 418提交
  • 题目来源 CodeForces 948A
  • 评测方式 RemoteJudge
  • 标签
  • 难度 入门难度
  • 时空限制 1000ms / 256MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 最新讨论 显示

    推荐的相关题目 显示

    题意翻译

    题目背景:(有少许简化和修改,但依然符合题意)

    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...
    

    说明

    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.

    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。