题目链接:

  http://codeforces.com/gym/100526

  http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11664&courseid=0

题目大意:

  总共N个点,现在有P个人,在T时间内要从起点S走到C个医疗站中的任意一个,M条X到Y的有向边,每条边每个单位时间可以通过的人数是pi,走完这条边耗时ti。

  人可以停留在任意一个点,求最多能有多少人到达医疗站。

  (1<=C<=N<=1000,0<=M<=1000,1<=P,T<=100,1<=pi,ti<=100)

题目思路:

  【最大流】

  SPFA居然T了。。

  将每个点按照时间拆点{X节点j时间的状态为点X(j)},把X到Y的边pi,ti拆成T-ti条边,每条边从X(j)到Y(j+ti)容量为pi,j为时间从0~T-ti,表示在j时间有pi个人可以从X到Y,到达Y的时间为j+ti。

  因为人可以停留在节点上所以X(i)到X(i+1)连一条容量P的边。

  每个医疗站的最终时间Ci(T)到超级汇T_T连一条容量为P的边(到达医疗站的人就无限停留直到时间为T到超级汇T_T)

  超级源S_S到起点S(0)连一条容量为P的边表示初始起点S有P个人。

  最终统计到达超级汇的人数即可。跑一遍最大流。

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 1004
#define M 104
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int s,p,t,S,T,nn;
int c[N];
int last[N*M+M],vd[N*M+M],d[N*M+M];
struct xxx
{
int next,to,q;
}a[N*M*M];
void add(int x,int y,int f)
{
a[++lll].next=last[x];
a[lll].to=y;
a[lll].q=f;
last[x]=lll;
}
int sap(int u,int f)
{
int i,v,tt,asp=,mix=nn-;
if(u==T)return f;
for(i=last[u];i;i=a[i].next)
{
v=a[i].to;
if(a[i].q>)
{
if(d[u]==d[v]+)
{
tt=sap(v,min(f-asp,a[i].q));
asp+=tt;
a[i].q-=tt;
a[i^].q+=tt;
if(asp==f || d[S]==nn)
return asp;
}
mix=min(mix,d[v]);
}
}
if(asp!=)return asp;
if(!--vd[d[u]])d[S]=nn;
else vd[d[u]=mix+]++;
return asp;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,f,dd;
for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s+1))
// while(~scanf("%d",&n))
{
ans=;lll=;mem(vd,);mem(d,);mem(last,);
scanf("%d%d%d%d%d",&n,&s,&p,&t,&cass);
S=n*t+t+;T=S+;
nn=T;vd[]=nn-t+;
add(S,t,p);
add(t,S,);
add(t,s*t+,p);
add(s*t+,t,);
for(i=;i<=n;i++)
{
for(j=;j<t;j++)
{
add(i*t+j,i*t+j+,p);
add(i*t+j+,i*t+j,);
}
}
for(i=;i<=cass;i++)
{
scanf("%d",&c[i]);
add(c[i]*t+t,T,p);
add(T,c[i]*t+t,);
}
scanf("%d",&m);
for(i=;i<=m;i++)
{
scanf("%d%d%d%d",&x,&y,&f,&dd);
for(j=;j+dd<=t;j++)
{
add(x*t+j,y*t+j+dd,f);
add(y*t+j+dd,x*t+j,);
}
if(x==s)
{
add(t,y*t+dd,f);
add(y*t+dd,t,);
}
}
while(d[S]<nn)
{
f=sap(S,MAX);
ans+=f;
}
printf("%d\n",ans);
}
return ;
}
/*
// //
*/

【最大流】BAPC2014 A Avoiding the Apocalypse (Codeforces GYM 100526)的更多相关文章

  1. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  2. 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  3. 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  4. 【宽搜】BAPC2014 J Jury Jeopardy (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  5. 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  6. 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  7. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  8. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  9. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

随机推荐

  1. java InputStream

    java InputStream 当为网络数据流是,不能以read为-1作为数据结束的尾. 而用下列案例获取数据. Log.v(TAG, "==========start========== ...

  2. HDFS的Java客户端操作代码(查看HDFS下所有的文件或目录)

    1.查看HDFS下所有的文件或目录 package Hdfs; import java.io.IOException; import java.net.URI; import org.apache.h ...

  3. C# 内存管理优化畅想----前言

    C#语法简洁.优雅,类库丰富,是我最喜爱的计算机语言,没有“之一”.但是,经过深入学习后发现,C#的内存管理,也就是通常所说的垃圾回收(GC)机制,虽然跟其他支持GC的语言相比,已经很优秀了,但与手动 ...

  4. Android Activity各启动模式的差异

    Activity共有四种启动模式:standard,singleTop,singleTask,singleInstance 为了方便描述和理解,布局文件.Manifest文件和各个java文件如下: ...

  5. 【转】iOS-Core-Animation-Advanced-Techniques(二)

    原文: http://www.cocoachina.com/ios/20150104/10816.html 视觉效果和变换 (四)视觉效果 嗯,园和椭圆还不错,但如果是带圆角的矩形呢? 我们现在能做到 ...

  6. Ubuntu 12.04下解决Rhythmbox Music Player乱码问题

    1.打开终端输入如下信息: $ sudo gedit ~/.profile 2.在打开的文档末尾加上如下两句: export GST_ID3_TAG_ENCODING=GBK:UTF-8:GB1803 ...

  7. Delphi ControlCount和ComponentCount的区别

    ComponentCount指打开的窗体所拥有的控件个数,包含所有子组件.孙组件(子组件内的子组件) 如上图,Form1的ComponentCount是13,而Panel1的ComponentCoun ...

  8. POJ 2186.Popular Cows (强连通)

    强连通缩点,统计入度为1的缩点后的点的个数 个数1的话输出这个强连通分量的点的数量 否则输出0: code /* Kosaraju算法,无向图的强连通分量,时间复杂度O(n+m) 思路: 按照图G的深 ...

  9. 自动化工具word文档批量转html

    企业有很多的科室,科室的每个人或多或少都会写一些文档,有些文档领导需要浏览,解决的办法是将编辑的文档打印出来,供领导浏览,或是为了节约企业成本,文档就在人与人这间或部门之间copy过来,copy过去. ...

  10. 我摘录的js代码

    1.修改样式 document.getElementByIdx( "div1").style.display = "none"; 2.鼠标悬停图标变小手 sty ...