[CCPC2019秦皇岛E] Escape

Link

https://codeforces.com/gym/102361/problem/E

Solution

观察到性质若干然后建图跑最大流即可。

我的 ISAP 被卡了,换成 Dinic 却过了。

#include <bits/stdc++.h>
using namespace std; const int maxn = 200005;
const int inf = 1e+9; #define reset(x) memset(x,0,sizeof x) int dis[maxn], ans, cnt = 1, s, t, pre[maxn * 10], nxt[maxn * 10], h[maxn], v[maxn * 10];
std::queue<int> q;
void make(int x, int y, int z) {
pre[++cnt] = y, nxt[cnt] = h[x], h[x] = cnt, v[cnt] = z;
pre[++cnt] = x, nxt[cnt] = h[y], h[y] = cnt;
}
bool bfs() {
memset(dis, 0, sizeof dis);
q.push(s), dis[s] = 1;
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = h[x]; i; i = nxt[i])
if (!dis[pre[i]] && v[i])
dis[pre[i]] = dis[x] + 1, q.push(pre[i]);
}
return dis[t];
}
int dfs(int x, int flow) {
if (x == t || !flow)
return flow;
int f = flow;
for (int i = h[x]; i; i = nxt[i])
if (v[i] && dis[pre[i]] > dis[x]) {
int y = dfs(pre[i], min(v[i], f));
f -= y, v[i] -= y, v[i ^ 1] += y;
if (!f)
return flow;
}
if (f == flow)
dis[x] = -1;
return flow - f;
} int T,n,m,a,b,p[105],e[105];
char c[105][105]; int calch(int i,int j)
{
return 3+((i-1)*m+j-1)*2;
}
int calcv(int i,int j)
{
return 4+((i-1)*m+j-1)*2;
}
int calcx(int i,int j)
{
return 3+2*n*m+((i-1)*m+j-1);
}
int calcy(int i,int j)
{
return 3+3*n*m+((i-1)*m+j-1);
} signed main()
{
ios::sync_with_stdio(false);
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&n,&m,&a,&b);
reset(dis); reset(pre); reset(nxt); reset(h); reset(v); cnt=1;
//cout<<calch(n,m)<<" "<<calcv(n,m)<<" "<<calcx(n,m)<<" "<<calcy(n,m)<<endl;
for(int i=1;i<=n;i++) scanf("%s",c[i]+1);
for(int i=1;i<=a;i++) scanf("%d",&p[i]);
for(int i=1;i<=b;i++) scanf("%d",&e[i]);
for(int i=1;i<=n-1;i++)
for(int j=1;j<=m;j++)
if(c[i][j]=='0' && c[i+1][j]=='0')
make(calcv(i,j),calcv(i+1,j),1),
make(calcv(i+1,j),calcv(i,j),1);
for(int i=1;i<=n;i++)
for(int j=1;j<=m-1;j++)
if(c[i][j]=='0' && c[i][j+1]=='0')
make(calch(i,j),calch(i,j+1),1),
make(calch(i,j+1),calch(i,j),1);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(c[i][j]=='0')
make(calch(i,j),calcv(i,j),1),
make(calcv(i,j),calch(i,j),1);
for(int i=1;i<=a;i++) if(c[1][p[i]]=='0') make(1,calcv(1,p[i]),1);
for(int i=1;i<=b;i++) if(c[n][e[i]]=='0') make(calcv(n,e[i]),2,1);
s=1;t=2;
ans = 0;
for (; bfs(); ans += dfs(s, inf));
if(ans == a) printf("Yes\n");
else printf("No\n");
}
}

[CCPC2019秦皇岛] E. Escape的更多相关文章

  1. [CCPC2019秦皇岛] F. Forest Program

    [CCPC2019秦皇岛 F] Link https://codeforces.com/gym/102361/problem/F Description 给定一个仙人掌,删去一些边可以让它变成一个森林 ...

  2. 2019CCPC 秦皇岛 E.Escape

    传送门 题意: 给出一个\(n*m\)的迷宫,有\(a\)个入口,\(b\)个出口. 现在有\(a\)个机器人都从入口出发,一开始方向默认为下,你可以选在在一些格子上面放置一个转向器,转向器有四种: ...

  3. Codeforces Gym 102361A Angle Beats CCPC2019秦皇岛A题 题解

    题目链接:https://codeforces.com/gym/102361/problem/A 题意:给定二维平面上的\(n\)个点,\(q\)次询问,每次加入一个点,询问平面上有几个包含该点的直角 ...

  4. 2019CCPC秦皇岛 E题 Escape(网络流)

    Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  5. 2019-ccpc秦皇岛现场赛

    https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...

  6. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  7. 简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  8. c#模拟js escape方法

    public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...

  9. 【BZOJ-1340】Escape逃跑问题 最小割

    1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 264  Solved: 121[Submit] ...

随机推荐

  1. 1-2.Kubectl命令行工具

    1.kubectl用法 $~: kubectl [command] [TYPE] [NAME] [flags] [command] 子命令.用于操作Kubernetes集群资源对象. 可取值:[cre ...

  2. excel 名次

    RANK.AVG 函数 全部显示 全部隐藏 返回一个数字在数字列表中的排位:数字的排位是其大小与列表中其他值的比值:如果多个值具有相同的排位,则将返回平均排位. 语法 RANK.AVG(number, ...

  3. Win10的Cortana小娜反应慢?试试这个方法

    https://www.ithome.com/html/win10/158466.htm Win10语音助手Cortana小娜可以为用户提供全面的搜索服务,不管是本地还是在线,都可以轻松找到结果.不过 ...

  4. 【新人赛】阿里云恶意程序检测 -- 实践记录11.10 - XGBoost学习 / 代码阅读、调参经验总结

    XGBoost学习: 集成学习将多个弱学习器结合起来,优势互补,可以达到强学习器的效果.要想得到最好的集成效果,这些弱学习器应当"好而不同". 根据个体学习器的生成方法,集成学习方 ...

  5. 卸载Windows控制面板的程序和功能中找不到的一些软件的方法

    卸载Windows控制面板的程序和功能中找不到的一些软件的方法 找到卸载程序进行卸载即可

  6. Python之filter()函数与替代实现

    介绍 filter(f,x)函数用于过滤序列并返回迭代器,结果保留x中f为True的元素,需要新的序列通过list()转换. 例子 过滤列表中的字符串,保留数字. >>> i = [ ...

  7. 什么人适合学习Django?

    什么人适合学习Django? 我觉得如果你能满足以下2个条件,你就可以果断地选择Django了. 你喜欢Python, 你对Web开发有热情. 学习Python和Django并不难,最重要的是你是否对 ...

  8. StyleLint 使用指南

    StyleLint 是『一个强大的.现代化的 CSS 检测工具』, 与 ESLint 类似, 是通过定义一系列的编码风格规则帮助我们避免在样式表中出现错误. 安装stylelint npm insta ...

  9. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) (排序)

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  10. AI 数学基础:概率分布,幂,对数

    1.概率分布  参考: https://blog.csdn.net/ZZh1301051836/article/details/89371412 p 2.幂次的意义 物理理解:幂次描述的是指数型的变化 ...