Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)A. Protect Sheep
http://codeforces.com/contest/948/problem/A
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.
6 6
..S...
..S.W.
.S....
..W...
...W..
......
Yes
..SD..
..SDW.
.SD...
.DW...
DD.W..
......
1 2
SW
No
5 5
.S...
...S.
S....
...S.
.S...
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.
题意就是给一个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的更多相关文章
- 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 由变化规则可得: ...
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow
题目链接 题意 每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...
- 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 ...
- 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 ...
- 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条路目前开启(即能走),剩下的都是关闭状态 定义: ...
- 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), 问, ...
- 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 ...
- 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution
题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...
- 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio
题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...
随机推荐
- Python笔记16-------类
1.类的定义 (1)#括号中要加入父类,如果没有则默认为object,万类之源 class 类名(父类): '类的文档字符串' 类体代码 若类什么都不做,则类只作为命名空间,仅作为一个容器. (2)类 ...
- 20190226-SecureCRT连接linux显示中文乱码
SecureCRT连接我的Ubuntu14时中文显示乱码 解决办法: 在session options里选择UTF-8
- Jenkins持续构建打包后端服务流程详解
背景运用场景及思路 1.为响应后端开发人员需求,提升项目开发过程效率,选择Jenkins持续构建,进行导包启动一键持续集成 思路: 使用jenkins自带,立即构建->SVN拉取代码,通过Jen ...
- 一个简单的 PC端与移动端的适配(通过UA)
只需在header引用个js文件, 原理就是判断UA里面的标识. 加下面代码添加到js文件,在头文件引用即可 var Pc_url = 'http://www.baidu.com'; //PC端网址 ...
- nodejs-路由(待补充)
path Router 1 2 3 4 5 var express = require('express'); var Router = express.Router(); Router.get('/ ...
- BA-WG-泰豪发电机
泰豪发电机的控制主板有2个端口,一个是RS232端口,一个是RS485端口,通常接网关需要将这个RS485的端口调整为modbus协议输出,再将modbus协议通过网关转换为bacnet / ip协议 ...
- Qunie——自我生成程序
Qunie是一段没有输入.但输出和它本身源代码同样的程序.本文无不论什么高深技术,纯属娱乐! 近期看到wikipedia的一个词条--Quine,简单介绍部分摘录于此,并简要翻译: A quine i ...
- JAVA程序设计(11)-----面对对象0基础设计 麻将 创建麻将牌 然后洗牌 发牌~ 恩 就这样
zzzzZZZZ 1.開始还想贴图的 实在太懒了-- 这是一张麻将 package com.lovo; import java.awt.Graphics; import java.awt.Image; ...
- Android接口和框架学习
Android接口和框架学习 缩写: HAL:HardwareAbstraction Layer.硬件抽象层 CTS:CompatibilityTest Suite,兼容性測试套件 Android让你 ...
- 全面具体介绍一个P2P网贷领域的ERP系统的主要功能
一般的P2P系统,至少包含PC站点的前端和后端.前端系统的功能.能够參考"P2P系统哪家强,功能事实上都一样" http://blog.csdn.net/fansunion ...