[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. sc 与 net 命令

    查看命令的帮助: help sc 或者 help net net: net start mysql  打开服务 net stop mysql 关闭服务 net pause mysql 暂停服务 sc ...

  2. Apache Flink 任意 Jar 包上传致 RCE 漏洞复现

    0x00 简介 Flink核心是一个流式的数据流执行引擎,其针对数据流的分布式计算提供了数据分布.数据通信以及容错机制等功能.基于流执行引擎,Flink提供了诸多更高抽象层的API以便用户编写分布式任 ...

  3. 关于iScroll在安卓移动端/chrome模拟移动端上下滑动卡顿问题处理!!!!真实可靠!!!已解决!!!

    滑动卡顿效果 安卓手机打开微信浏览网页,Chrome模拟手机浏览网页,都出现的问题滑动卡顿! 修改代码点: 1.    <style type="text/css">  ...

  4. thinkphp 5.0 后台数据修改

    html代码 <table class="easyui-datagrid" data-options="singleSelect:true,collapsible: ...

  5. .net mvc中epplus导出excel

    帮助类 using OfficeOpenXml; using OfficeOpenXml.Style; using System; using System.Collections.Generic; ...

  6. PHPMailer发送邮件遇坑小记

    一:phpmailer发送邮件成功了 数据库发送状态也更改 但是用户就是没收到邮件. 出现原因:发送邮件太多 导致邮箱服务器被腾讯封了 发送的邮件统统进入了邮件服务器的草稿箱里. 解决方案: 重新修改 ...

  7. Python标准库之re模块

    re模块用于正则表达式. 正则表达式在线测试:http://c.runoob.com/front-end/854 正则表达式元字符可以参考:https://www.w3cschool.cn/zheng ...

  8. 初识XXE漏洞

    本文是参照本人觉得特别仔细又好懂的一位大佬的文章所做的学习笔记 大佬的链接:https://www.cnblogs.com/zhaijiahui/p/9147595.html#autoid-0-0-0 ...

  9. Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your My

    转自:https://blog.csdn.net/haha_66666/article/details/78444457 Query : select * from order LIMIT 0, 10 ...

  10. Codeforces 474B. Worms

    It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mo ...