传送门

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 =)的更多相关文章

  1. SGU438 The Glorious Karlutka River =)(最大流)

    题目大概说有m个人要过一条宽W的河,人最远跳远距离是d,河上有n个垃圾堆,每个垃圾堆都有坐标和同一时间能容纳的人数,问所有人最少要跳几次才能跳到对岸. 又是一题根据时间拆点的最大流. 二分时间建容量网 ...

  2. SGU 438 The Glorious Karlutka River =)(最大流)

    Description A group of Mtourists are walking along the Karlutka river. They want to cross the river, ...

  3. The Glorious Karlutka River =)

    sgu438:http://acm.sgu.ru/problem.php?contest=0&problem=438 题意:有一条东西向流淌的河,宽为 W,河中有 N 块石头,每块石头的坐标( ...

  4. SGU 438 The Glorious Karlutka River =) ★(动态+分层网络流)

    [题意]有一条东西向流淌的河,宽为W,河中有N块石头,每块石头的坐标(Xi, Yi)和最大承受人数Ci已知.现在有M个游客在河的南岸,他们想穿越这条河流,但是每个人每次最远只能跳D米,每跳一次耗时1秒 ...

  5. SGU 0438 The Glorious Karlutka River =) 动态流

    题目大意:有一条东西向流淌的河,宽为W,河中有N块石头,每块石头的坐标(Xi, Yi)和最大承受人数Ci已知.现在有M个游客在河的南岸,他们想穿越这条河流,但是每个人每次最远只能跳D米,每跳一次耗时1 ...

  6. SGU438_The Glorious Karlutka River =)

    好题,有一些人在河的一边,想通过河里的某些点跳到对岸去.每个点最多只能承受一定数量的人,每人跳跃一次需要消耗一个时间.求所有人都过河的最短时间. 看网上说是用了什么动态流的神奇东东.其实就是最大流吧, ...

  7. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  8. Moon River

    读书笔记系列链接地址http://www.cnblogs.com/shoufengwei/p/5714661.html.        昨晚无意中听到了一首英文歌曲,虽不知其意,但是瞬间就被优美的旋律 ...

  9. poj[3093]Margaritas On River Walk

    Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...

随机推荐

  1. CALayer的mask属性

    可以对图层按path进行指定裁剪 //#import "ViewController.h" // //@interface ViewController () // //@end ...

  2. 集训队8月9日(组合计数+容斥原理+Mobius函数)

    刷题数:4 今天看了组合计数+容斥原理+Mobius函数,算法竞赛进阶指南169~179页 组合计数 https://www.cnblogs.com/2462478392Lee/p/11328938. ...

  3. [HDU2604]Queuing

    题目:Queuing 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2604 分析: 1)将当前格和上一格合并当作一个状态,考虑下一个格子放0(m)还是1( ...

  4. 初步认识pug

    一.初步认识pug 1.所谓的pug就是我们之前说的jade,也就是一种通过缩进的方式来编写代码的过程,在编译的过程中,我们不需要考虑标签是否闭合的问题.此外,用这种编译方式,加快了我们写代码的速度, ...

  5. js俩习题

    需求,现在要求两个按钮,点击1,背景为红色,点击2,背景为黄色 *****html代码——————————————————————————————————————————————————<!DO ...

  6. SVG开发包, 20 个有用的 SVG 工具,提供更好的图像处理

    20 个有用的 SVG 工具,提供更好的图像处理 SVG 现正在 Web 设计领域变得越发流行, 你可以使用 Illustrator 或者 Inkscape 来创建 SVG 图像. 但当进行 Web ...

  7. CPU C-States Power Saving Modes

    http://www.hardwaresecrets.com/article/611 Everything You Need to Know About the CPU C-States Power ...

  8. selenium2-java 浏览器的三种弹窗处理

    alert弹窗 confirm弹窗 prompt弹窗 点击确定         // 选取警告弹窗           Alert alert=driver.switchTo().alert();   ...

  9. Linux操作系统(四)_部署MySQL

    一.部署过程 1.当前服务器的内核版本和发行版本 cat /etc/issue uname -a 2.检查系统有没有自带mysql,并卸载自带版本 yum list installed | grep ...

  10. 科普:std::sort干了什么

    std::sort算是STL中对OIer比较友好的函数了,但你有想过sort是如何保证它的高速且稳定吗? 正文 我们首先来到第一层:sort函数 template<typename _Rando ...