2019CCPC秦皇岛 E题 Escape(网络流)
Escape
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 16 Accepted Submission(s): 12
There are a robots above the maze. For i-th robot, it is initially positioned exactly above the cell (1, pi), which can be described as (0, pi). And the initial moving direction of the robots are all downward, which can be written as (1, 0) in the vector form.
Also, there are b exits below the maze. For i-th exit, it is positioned exactly below the cell (n, ei), which can be described as (n + 1, ei).
Now, you want to let the robots escape from the maze by reaching one of the exits. However, the robots are only able to go straight along their moving directions and can’t make a turn. So you should set some turning devices on some blank cells in the maze to help the robots make turns.
There are 4 types of turning devices:
- “NE-devices” : make the robots coming from above go rightward, and make the robots coming from right go upward. Coming from left or below is illegal.
- “NW-devices” : make the robots coming from above go leftward, and make the robots coming from left go upward. Coming from right or below is illegal.
- “SE-devices” : make the robots coming from below go rightward, and make the robots coming from right go downward. Coming from left or above is illegal.
- “SW-devices” : make the robots coming from below go leftward, and make the robots coming from left go downward. Coming from right or above is illegal.
For each cell, the number of turning devices on it can not exceed 1. And collisions between the robots are ignored, which allows multiple robots to visit one same cell even at the same time.
You want to know if there exists some schemes to set turning devices so that all the a robots can reach one of the b exits after making a finite number of moves without passing a blocked cell or passing a turning device illegally or going out of boundary(except the initial position and the exit).
If the answer is yes, print “Yes” in a single line, or print “No” if the answer is no.
For each test case:
The first line contains four positive integers n, m, a, b (1 ≤ n, m ≤ 100, 1 ≤ a, b ≤ m), denoting the number of rows and the number of columns in the maze, the number of robots and the number of exits respectively.
Next n lines each contains a string of length m containing only “0” or “1”, denoting the initial maze, where cell (i, j) is blank if the j-th character in i-th string is “0”, while cell (i, j) is blocked if the j-th character in i-th string is “1”.
The next line contains a integers pi (1 ≤ pi ≤ m), denoting the initial positions (0, pi) of the robots.
The next line contains b integers ei (1 ≤ ei ≤ m), denoting the positions (n + 1, ei) of the exits.
It is guaranteed that all pis are pairwise distinct and that all eis are also pairwise distinct.
3 4 2 2
0000
0011
0000
1 4
2 4
3 4 2 2
0000
0011
0000
3 4
2 4
No
题解:
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=,M=;
int T,n,m,a,b,h[N],s,t,base;
char g[][];
int head[N],nex[M],w[M],to[M],tot;
inline void ade(int a,int b,int c)
{
to[++tot]=b;
nex[tot]=head[a];
w[tot]=c;
head[a]=tot;
}
inline void add(int a,int b,int c)
{
ade(a,b,c);
ade(b,a,);
}
inline int id(int x,int y){return m*x+y;}
inline int bfs()
{
memset(h,,sizeof h);
h[s]=;
queue<int> q; q.push(s);
while(q.size())
{
int u=q.front(); q.pop();
for(int i=head[u];i;i=nex[i])
{
if(!h[to[i]]&&w[i])
{
h[to[i]]=h[u]+;
q.push(to[i]);
}
}
}
return h[t];
}
int dfs(int x,int f)
{
if(x==t) return f;
int fl=;
for(int i=head[x];i&&f;i=nex[i])
{
if(h[to[i]]==h[x]+&&w[i])
{
int mi=dfs(to[i],min(w[i],f));
w[i]-=mi; w[i^]+=mi; fl+=mi; f-=mi;
}
}
if(!fl) h[x]=-;
return fl;
}
int dinic()
{
int res=;
while(bfs()) res+=dfs(s,inf);
return res;
}
signed main()
{
cin>>T;
while(T--)
{
tot=;
memset(head,,sizeof head);
cin>>n>>m>>a>>b;
base=(n+)*m; t=base*;
for(int i=;i<=n;i++) scanf("%s",g[i]+);
for(int i=;i<=a;i++)
{
int x; scanf("%d",&x); g[][x]='';
add(s,id(,x),); add(id(,x),id(,x),);
}
for(int i=;i<=b;i++)
{
int x; scanf("%d",&x);
g[n+][x]='';
add(id(n+,x),t,inf);
add(id(n,x),id(n+,x),inf);
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(g[i][j]=='') continue;
if(i>) add(id(i,j),id(i-,j),);
if(i<n) add(id(i,j),id(i+,j),);
if(j>) add(id(i,j)+base,id(i,j-)+base,);
if(j<m) add(id(i,j)+base,id(i,j+)+base,);
add(id(i,j),id(i,j)+base,);add(id(i,j)+base,id(i,j),);
}
}
puts(dinic()==a?"Yes":"No");
}
return ;
}
2019CCPC秦皇岛 E题 Escape(网络流)的更多相关文章
- 2019CCPC秦皇岛D题 Decimal
Decimal Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- 2019CCPC秦皇岛I题 Invoker(DP)
Invoker Time Limit: 15000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- 2019CCPC 秦皇岛 E.Escape
传送门 题意: 给出一个\(n*m\)的迷宫,有\(a\)个入口,\(b\)个出口. 现在有\(a\)个机器人都从入口出发,一开始方向默认为下,你可以选在在一些格子上面放置一个转向器,转向器有四种: ...
- 2019-ccpc秦皇岛现场赛
https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...
- 2017 CCPC秦皇岛 L题 One Dimensions Dave
BaoBao is trapped in a one-dimensional maze consisting of grids arranged in a row! The grids are nu ...
- 2019CCPC秦皇岛自我反省&部分题解
练了一年半了,第一次打CCPC,险些把队友坑了打铁,最后也是3题危险捡了块铜. 非常水的点双连通,我居然不相信自己去相信板子,唉,结果整来整去,本来半个小时能出的题,整到了3个小时,大失误呀,不然就可 ...
- 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches
Drainage Ditches 题目抽象:给你m条边u,v,c. n个定点,源点1,汇点n.求最大流. 最好的入门题,各种算法都可以拿来练习 (1): 一般增广路算法 ford() #in ...
- hdu 3572 Escape 网络流
题目链接 给一个n*m的图, 里面有一些点, '.'代表空地, '#'代表墙, 不可以走, '@'代表大门, 可以有多个, 'X'代表人, 问所有人都走出大门需要的最短时间, 每一时刻一个格子只能有一 ...
- POJ 2455 网络流 基础题 二分+网络流 dicnic 以及 sap算法
Secret Milking Machine Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8189 Accepted: ...
随机推荐
- java线程池的介绍与使用(Executor框架)
1. 先来看一下类构成 public interface Executor { //顶级接口Executor,定义了线程执行的方法 void execute(Runnable command); } ...
- SpEL + AOP实现注解的动态赋值
一.自定义注解 先聊聊这个需求,我需要根据用户的权限对数据进行一些处理,但是痛点在哪里呢?用户的权限是在请求的时候知道的,我怎么把用户的权限传递给处理规则呢?想了以下几种方案: Mybatis 拦截器 ...
- JenKins结合cppcheck及cpplint进行代码风格及静态代码检测
JenKins结合cppcheck及cpplint 最近公司需要在Jenkins上安装cppcheck及cpplint进行代码风格及静态代码检测,这里记录下过程. 前提条件 安装了Jenkins 步骤 ...
- nyoj 98-成绩转换 (if, else if)
98-成绩转换 内存限制:64MB 时间限制:3000ms 特判: No 通过数:49 提交数:74 难度:1 题目描述: 输入一个百分制的成绩M,将其转换成对应的等级,具体转换规则如下: 90~10 ...
- systemd管理
systemd是为改进传统系统启动方式而退出的Linux系统管理工具,现已成为大多数Linux发行版的标准配置 systemd与系统初始化 Linux系统启动过程中,当内核启动并完成装载跟文件系统后, ...
- 函数式接口的使用 (Function、Predicate、Supplier、Consumer)
参考:https://blog.csdn.net/jmj18756235518/article/details/81490966 函数式接口 定义:有且只有一个抽象方法的接口 Function< ...
- 万恶之源-python基本数据类型
万恶之源-基本数据类型(dict) 本节主要内容: 字典的简单介绍 字典增删改查和其他操作 3. 字典的嵌套 ⼀一. 字典的简单介绍 字典(dict)是python中唯⼀一的⼀一个映射类型.他是以{ ...
- PHP抓取远程图片教程(包含不带后缀图片)
之前做微信登录开发时候,发现微信头像图片没有后缀名,传统的图片抓取方式不奏效,需要特殊的抓取处理.所以,后来将各种情况结合起来,封装成一个类,分享出来. 创建项目 作为演示,我们在www根目录创建项目 ...
- mui开发:苹果手机自动全屏解决方案
前一段时间,使用mui写app时,出现了苹果手机播放视频时,自动全屏的情况,并且无法点击控件,只能等到播放完毕后点击控件. 那么怎么解决这个问题呢,弟弟们请看我的下面. 1.在页面的video标签中, ...
- P1035 级数求和
题目描述 已知:S_n= 1+1/2+1/3+…+1/nSn=1+1/2+1/3+…+1/n.显然对于任意一个整数KK,当nn足够大的时候,S_nSn大于KK. 现给出一个整数KK(1 \le k ...