SGU438 The Glorious Karlutka River =)
传送门
sgu原来搬到cf了呀点了好几个链接才找到233
传说中的动态流(?)
反正很暴力就对了QwQ
有容量限制->拆点 对于每个点拆成入点和出点
时间限制->分层 对于每个时刻的每个石头都建点
所以源点连最开始的到达的石头的入点 然后每个可以到达的出点连汇点
然后每个时刻的入点出点之间连接流量为C 然后可以互相跳的连inf
枚举时刻在残存网络上继续流可以了 直到一个时刻 >=m 就是所有人都跳过去了QwQ
附代码。
我觉得我这份代码巨好看(大雾)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define inf 20021225
#define ll long long
#define mxn 42010
#define mxm 960010
using namespace std;
queue<int> que;
struct point{int x,y,c;}p[51];
struct edge{int to,lt,f;}e[mxm<<1];
int in[mxn],cnt=1,dep[mxn],s,t,n,m,d,w;
void add(int x,int y,int f){e[++cnt].to=y;e[cnt].lt=in[x];e[cnt].f=f;in[x]=cnt;}
void addedge(int x,int y,int f){add(x,y,f);add(y,x,0);}
bool bfs()
{
while(!que.empty()) que.pop();
memset(dep,0,sizeof(dep));
dep[s]=1;que.push(s);
while(!que.empty())
{
int x=que.front();que.pop();
for(int i=in[x];i;i=e[i].lt)
{
int y=e[i].to;
if(!dep[y]&&e[i].f)
{
dep[y]=dep[x]+1;
if(y==t) return 1;
que.push(y);
}
}
}
return 0;
}
int dfs(int x,int flow)
{
if(x==t||!flow) return flow;
int cur=flow;
for(int i=in[x];i;i=e[i].lt)
{
int y=e[i].to;
if(dep[y]==dep[x]+1&&e[i].f)
{
int tmp=dfs(y,min(cur,e[i].f));
cur-=tmp;e[i].f-=tmp;e[i^1].f+=tmp;
if(!cur) return flow;
}
}
dep[x]=-1;
return flow-cur;
}
int dinic()
{
int ans=0;
while(bfs())
ans+=dfs(s,inf);
//printf("%d\n",ans);
return ans;
}
int id(int x,int dep){return dep*m+x;}
int dis(point a,point b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
bool jump(point a,point b){return dis(a,b)<=d*d;}
bool st[51],fn[51];
int main()
{
scanf("%d%d%d%d",&n,&m,&d,&w);
s=mxn-4;t=s+1;
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].c);
if(p[i].y<=d) st[i]=1;
if(p[i].y>=w-d) fn[i]=1;
}
if(w<=d){printf("1\n");return 0;}
int tot=0,tm;
for(tm=0;tm<n+m;tm++)
{
for(int i=1;i<=n;i++)
{
if(st[i]) addedge(s,id(i,tm<<1),inf);
if(fn[i]) addedge(id(i,tm<<1|1),t,inf);
addedge(id(i,tm<<1),id(i,tm<<1|1),p[i].c);
}
tot+=dinic();
if(tot>=m) break;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j) continue;
if(jump(p[i],p[j])) addedge(id(i,tm<<1|1),id(j,tm+1<<1),inf);
}
}
}
if(tm<n+m) printf("%d\n",tm+2);
else printf("IMPOSSIBLE\n");
return 0;
}
SGU438 The Glorious Karlutka River =)的更多相关文章
- SGU438 The Glorious Karlutka River =)(最大流)
题目大概说有m个人要过一条宽W的河,人最远跳远距离是d,河上有n个垃圾堆,每个垃圾堆都有坐标和同一时间能容纳的人数,问所有人最少要跳几次才能跳到对岸. 又是一题根据时间拆点的最大流. 二分时间建容量网 ...
- SGU 438 The Glorious Karlutka River =)(最大流)
Description A group of Mtourists are walking along the Karlutka river. They want to cross the river, ...
- The Glorious Karlutka River =)
sgu438:http://acm.sgu.ru/problem.php?contest=0&problem=438 题意:有一条东西向流淌的河,宽为 W,河中有 N 块石头,每块石头的坐标( ...
- SGU 438 The Glorious Karlutka River =) ★(动态+分层网络流)
[题意]有一条东西向流淌的河,宽为W,河中有N块石头,每块石头的坐标(Xi, Yi)和最大承受人数Ci已知.现在有M个游客在河的南岸,他们想穿越这条河流,但是每个人每次最远只能跳D米,每跳一次耗时1秒 ...
- SGU 0438 The Glorious Karlutka River =) 动态流
题目大意:有一条东西向流淌的河,宽为W,河中有N块石头,每块石头的坐标(Xi, Yi)和最大承受人数Ci已知.现在有M个游客在河的南岸,他们想穿越这条河流,但是每个人每次最远只能跳D米,每跳一次耗时1 ...
- SGU438_The Glorious Karlutka River =)
好题,有一些人在河的一边,想通过河里的某些点跳到对岸去.每个点最多只能承受一定数量的人,每人跳跃一次需要消耗一个时间.求所有人都过河的最短时间. 看网上说是用了什么动态流的神奇东东.其实就是最大流吧, ...
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- Moon River
读书笔记系列链接地址http://www.cnblogs.com/shoufengwei/p/5714661.html. 昨晚无意中听到了一首英文歌曲,虽不知其意,但是瞬间就被优美的旋律 ...
- poj[3093]Margaritas On River Walk
Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...
随机推荐
- 第三周作业—N42-虚怀若谷
一.显示/etc/目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录 ls /etc/[^[:alpha:]][[:alpha:]]* 二.复制/etc/目录下所有以p开头的 ...
- 【LeetCode 84】柱状图中最大的矩形
题目链接 [题解] 维护一个单调递增的栈. 会发现栈内的第i个元素的前面一个(i-1)元素在原始的序列中的数字 都是要高于第i个元素的.(或者没有元素) 那么第i个元素往左最多可以扩展到第i-1个元素 ...
- myeclipse svn重新定位 本地文件 svn 重新定位
我们在用工具myeclipse开发项目时,当资源库存储空间不够时,我们就需要添加资源库,涉及到我们切换项目资源库,下面就介绍一下svn资源库重新定位步骤 1,window到show view到othe ...
- BUUCTF | CODE REVIEW 1 (反序列化,md5绕过)
<?php /** * Created by PhpStorm. * User: jinzhao * Date: 2019/10/6 * Time: 8:04 PM */ highlight_f ...
- NGINX配置之二: nginx location proxy_pass 后面的url 加与不加/的区别.
这里我们分4种情况讨论 这里我们请求的网站为:192.168.1.123:80/static/a.html 整个配置文件是 server{ port 80, server name 192.168.1 ...
- 使用xorm将结构体转为sql文件
操作步骤 (1)定义结构体 type User struct { Id int //表id Name string //姓名 ...}12345(2)编写代码,执行自动增量同步(mysql为例) im ...
- identityserver4踩坑总结
1.在配置id4服务端的时候要注意client里面的 AllowedScopes开放的值要和GetIdentityResources中加入的值是一样的,不然调用以后报{"error" ...
- SercletConfig 详解
ServletConfig:从一个servlet被实例化后,对任何客户端在任何时候访问有效,但仅对本servlet有效,一个servlet的ServletConfig对象不能被另一个servlet访问 ...
- Seq2Seq和Attention机制入门介绍
1.Sequence Generation 1.1.引入 在循环神经网络(RNN)入门详细介绍一文中,我们简单介绍了Seq2Seq,我们在这里展开一下 一个句子是由 characters(字) 或 w ...
- C# String相关
1.去掉字符串中的所有的空 string s = " select * from \r\n where a =b "; s = Regex.Replace(s, @"\s ...