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 ...
随机推荐
- 警惕黑客利用新方法绕过Office安全链接
东方联盟黑客安全研究人员透露,一些黑客已经发现绕过MicrosoftOffice365的安全功能,该功能最初旨在保护用户免受恶意软件和网络钓鱼攻击. 被称为安全链接的功能已被包含在Office365软 ...
- 用pycharm运行pytest
安装pytest 1. 在pycharm中建项目,建文件,文件名字要以test_开头 2.在文件中插入pytest模块 import pytest #引用pytest模块 3.定义test函数,以及断 ...
- python模块之jinja2 ,shutil
一 jinja2 用来给python提供html语法的模块 安装 pip install jinja2 使用 from jinja2 import Template def html_output(p ...
- 前端-PC端瀑布流【10张图】
.HTML 利用封装的 jquerywaterfall.js 方法 完成 <!DOCTYPE html> <html lang="en"> <head ...
- boost graph
Boost Graph provides tools to work with graphs. Graphas are two-dimensional point clouds with any nu ...
- 【BZOJ3522&BZOJ4543】Hotel加强版(长链剖分,树形DP)
题意:求一颗树上三点距离两两相等的三元组对数 n<=1e5 思路:From https://blog.bill.moe/bzoj4543-hotel/ f[i][j]表示以i为根的子树中距离i为 ...
- paper 159:文章解读:From Facial Parts Responses to Face Detection: A Deep Learning Approach--2015ICCV
文章链接:https://arxiv.org/pdf/1509.06451.pdf 1.关于人脸检测的一些小小总结(Face Detection by Literature) (1)Multi-vie ...
- [USACO09DEC] Video Game Troubles
背包DP:有依赖的背包问题 #include <cstdio> #include <cstdlib> #include <cmath> #include <c ...
- VB.NET导出Excel 轻松实现Excel的服务器与客户端交换 服务器不安装Office
说来VB.Net这个也是之前的一个项目中用到的.今天拿来总结下用途,项目需求,不让在服务器安装Office办公软件.这个也是煞费了一顿. 主要的思路就是 在导出的时候,利用DataTable做中间变量 ...
- MAC使用命令行打包出ipa包-通过xcodeproj
参考 : https://www.jianshu.com/p/32af2f71b4e5--老了,里面的一些命令现在都没有了,但可以借鉴思路 https://www.jianshu.com/p/004c ...