hdu 3572 Task Schedule(邻接表dinic)
来源:互联网 发布:网络用语bgm是什么意思 编辑:程序博客网 时间:2024/05/22 09:40
Task Schedule
Problem Description
Our geometry princess XMM has stoped her study in computational geometry to concentrate on her newly opened factory. Her factory has introduced M new machines in order to process the coming N tasks. For the i-th task, the factory has to start processing it at or after day Si, process it for Pi days, and finish the task before or at day Ei. A machine can only work on one task at a time, and each task can be processed by at most one machine at a time. However, a task can be interrupted and processed on different machines on different days.
Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
Input
On the first line comes an integer T(T<=20), indicating the number of test cases.
You are given two integer N(N<=500) and M(M<=200) on the first line of each test case. Then on each of next N lines are three integers Pi, Si and Ei (1<=Pi, Si, Ei<=500), which have the meaning described in the description. It is guaranteed that in a feasible schedule every task that can be finished will be done before or at its end day.
You are given two integer N(N<=500) and M(M<=200) on the first line of each test case. Then on each of next N lines are three integers Pi, Si and Ei (1<=Pi, Si, Ei<=500), which have the meaning described in the description. It is guaranteed that in a feasible schedule every task that can be finished will be done before or at its end day.
Output
For each test case, print “Case x: ” first, where x is the case number. If there exists a feasible schedule to finish all the tasks, print “Yes”, otherwise print “No”.
Print a blank line after each test case.
Print a blank line after each test case.
Sample Input
24 31 3 5 1 1 42 3 73 5 92 22 1 31 2 2
Sample Output
Case 1: Yes Case 2: Yes
Author
allenlowesy
Source
2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC
Recommend
zhouzeyong | We have carefully selected several similar problems for you: 1532 3491 1533 3416 3081
邻接表dinic没什么好说的,dinic相对于朴素增广路算法就是增加了层次图,每次取消所有同层次点之间的边(为什么是对的呢?因为如果计算完当前层次图的话,如果现在同层次之间的边会成为下次层次图中不同层次的边,然后所有情况都会被计算进去),如果一个点的层次比终点的层次大(怎么办呢?计算完当前层次图之后,如果这个点与终点联通,在不断计算层次图的过程中,迟早会出现只有通过这个点的路还联通终点的情况,这样这个点的层次在这次计算就比终点的层次小了)
#include<cstdio>#include<cstring>#include<queue>using namespace std;#define N 1005const int inf=0x7ffffff;int cnt,n,m,t;int head[N],dist[N];struct node{ int u,v,w,next;}edge[N*N];int min(int x,int y){ return x>y?y:x;}void add(int u,int v,int w){ edge[cnt].u=u; edge[cnt].v=v; edge[cnt].w=w; edge[cnt].next=head[u]; head[u]=cnt++; edge[cnt].u=v; edge[cnt].v=u; edge[cnt].w=0; edge[cnt].next=head[v]; head[v]=cnt++;}int bfs()//寻早新的层次图{ int i,u,v; queue<int>q; memset(dist,0,sizeof(dist)); u=0; dist[u]=1; q.push(u); while(!q.empty()) { u=q.front(); q.pop(); for(i=head[u];i!=-1;i=edge[i].next) { v=edge[i].v; if(edge[i].w&&!dist[v]) { dist[v]=dist[u]+1; if(v==t) return 1; q.push(v); } } } return 0;}int dfs(int s,int lim)//lim记录当前路上的最大流{ int i,tmp,v,cost=0; if(s==t) return lim; for(i=head[s];i!=-1;i=edge[i].next) { v=edge[i].v; if(edge[i].w&&dist[s]==dist[v]-1)//前往下一个层次 { tmp=dfs(v,min(lim-cost,edge[i].w)); if(tmp>0) { edge[i].w-=tmp; edge[i^1].w+=tmp; cost+=tmp; if(cost==lim) break; } else dist[v]=-1; } } return cost;}int dinic(){ int ans=0,s=0; while(bfs())//搜索当前层次图 ans+=dfs(s,inf);//若层次图存在,则将当前层次图所有可增广的路都增广 return ans;}int main(){ freopen("C:\\Users\\Administrator\\Desktop\\input.txt","r",stdin); int i,j,T,sum,t1,t2,cas=1; int s[N],e[N],p[N]; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); t1=N;t2=0; sum=0; for(i=1;i<=n;i++) { scanf("%d%d%d",&p[i],&s[i],&e[i]); t1=min(t1,s[i]); t2=max(t2,e[i]); sum+=p[i]; } cnt=0; memset(head,-1,sizeof(head)); for(i=1;i<=n;i++) { add(0,i,p[i]); } t=n+t2-t1+1+1; for(i=1;i<=n;i++) { for(j=s[i];j<=e[i];j++) { add(i,n+j-t1+1,1); } } for(i=t1;i<=t2;i++) add(n+i-t1+1,t,m); if(sum==dinic()) printf("Case %d: Yes\n\n",cas++); else printf("Case %d: No\n\n",cas++); } return 0;}
0 0
- hdu 3572 Task Schedule(邻接表dinic)
- HDU 3572 Task Schedule (DINIC 邻接表实现)
- hdu 3572 Task Schedule (dinic算法)
- hdu 3572 Task Schedule(dinic)
- HDU 3572 Task Schedule(dinic)
- HDU 3572 Task Schedule(最大流-Dinic)
- HDU 3572 Task Schedule(最大流Dinic算法)
- HDU ACM 3572 Task Schedule 网络最大流->dinic算法
- hdu 3572 Task Schedule【最大流Dinic-----建图】
- hdu 3572 Task Schedule 最大流+建图+dinic入门
- hdu 3572 Task Schedule 最大流 Dinic算法
- hdu 3572 Task Schedule(最大流&&建图经典&&dinic)
- hdu 3527 Task Schedule 最大流 Dinic
- hdu3572 Task Schedule 网络流(Dinic)
- hdu3572 Task Schedule(最大流dinic)
- hdu 3572 Task Schedule
- HDU 3572 Task Schedule
- hdu 3572 Task Schedule
- 具有互联网精神的创意设计镜子
- 关于iOS多线程,你看我就够了
- 程序中上下文Context
- maven学习(下)利用Profile构建不同环境的部署包
- Spring之——quartz集群的问题及解决方案(基于Spring4.0+quartz2.2.1的集群架构)
- hdu 3572 Task Schedule(邻接表dinic)
- poj 1948(搜索+剪枝)
- Hibernate 映射多对多关联关系
- Can't load IA 32-bit .dll on a AMD 64-bit platform
- jQuery.inArray判断指定值在数组是否存在
- 字符串加密解密
- 华为机型 cordova-plugin-camera从图库获取报错
- js如何查找数组中是否存在某个值
- Matlab灰色预测和统计分析