hdoj Task Schedule 3572 (最大流变型判断是否满流)
来源:互联网 发布:明泰科技 建站 编辑:程序博客网 时间:2024/05/16 17:21
Task Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6010 Accepted Submission(s): 1925
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//要将图转化一下。建立一个源点,一个汇点。将图连通。。。具体看代码#include<stdio.h>#include<string.h>#include<queue>#include<algorithm>#define N 1010#define INF 0x3f3f3f3fusing namespace std; int head[N],edgenum;int c[N];int dis[N];int vis[N];int n,m;struct zz{int from;int to;int cap;int flow;int next;}edge[N*1000];void add(int u,int v,int w){zz E={u,v,w,0,head[u]};edge[edgenum]=E;head[u]=edgenum++;zz EE={v,u,0,0,head[v]};edge[edgenum]=EE;head[v]=edgenum++;}queue<int>q;bool bfs(int s,int e){memset(dis,-1,sizeof(dis));memset(vis,0,sizeof(vis));while(!q.empty())q.pop();q.push(s);dis[s]=0;vis[s]=1;while(!q.empty()){int u=q.front();q.pop();for(int i=head[u];i!=-1;i=edge[i].next){zz v=edge[i];if(!vis[v.to]&&v.cap>v.flow){dis[v.to]=dis[u]+1;vis[v.to]=1;if(v.to==e)return true;q.push(v.to);}}}return false;}int dfs(int x,int a,int e){if(x==e||a==0)return a;int flow=0,f;for(int &i=c[x];i!=-1;i=edge[i].next){zz &v=edge[i];if(dis[v.to]==dis[x]+1&&(f=dfs(v.to,min(a,v.cap-v.flow),e))>0){v.flow+=f;edge[i^1].flow-=f;flow+=f;a-=f;if(a==0)break;}}return flow;}int maxflow(int s,int e){int flow=0;while(bfs(s,e)){memcpy(c,head,sizeof(head));flow+=dfs(s,INF,e);}return flow;}int sum,ee;int main(){int t;int T=1;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);edgenum=0;memset(head,-1,sizeof(head));int mm=0;sum=0;int u,v,w;for(int i=1;i<=n;i++){scanf("%d%d%d",&w,&u,&v);sum+=w;add(0,i,w);mm=max(mm,v);for(int j=u;j<=v;j++)add(i,n+j,1);}ee=n+mm+1;for(int i=1;i<=mm;i++)add(n+i,ee,m);printf("Case %d: ",T++);if(maxflow(0,ee)>=sum)printf("Yes\n\n");elseprintf("No\n\n");}return 0;}
0 0
- hdoj Task Schedule 3572 (最大流变型判断是否满流)
- hdoj 3572 Task Schedule 【最大流 在时间区间建图判断是否满流】
- Task Schedule 【最大流 判断是否满流】
- hdoj 3572 Task Schedule【最大流】
- hdu3572 Task Schedule(Dinic判断是否满流)
- hdu 3572 Task Schedule(最大流,判断满流+isap模版)
- HDOJ 3572 - Task Schedule 读清题..简单的构图最大流
- hdu 3572 Task Schedule(最大流)
- HDU - 3572 Task Schedule (最大流)
- HDU3572——Task Schedule (最大流判断满流)
- hdu3572-Task Schedule(最大流(ISAP),是否满流)
- hdoj 3572 Task Schedule
- Hdu 3572 Task Schedule [最大流] 任务分配,判断满流
- HDU 3572 Task Schedule ([最大流]任务分配,判断满流)
- HDOJ-3572 Task Schedule(网络流)
- HDU 3572Task Schedule(网络流之最大流)
- hdu 3572 Task Schedule(网络流最大流)
- HDU 3572 Task Schedule(最大流问题,sap算法)
- 剑指offer 替换空格
- UITableView中没有数据时,让其不显示下划线的两种方法
- 文本建模
- 开源业务规则引擎JBoss Drools入门介绍 Demo示例
- Solr之缓存篇
- hdoj Task Schedule 3572 (最大流变型判断是否满流)
- 黑马王子讲座:黄金十字架战法
- IE11兼容性问题
- Automatic Property Synthesis With Xcode 4.4
- 桶排序算法之Java实现
- java厚积薄发之String常用方法
- leetcode-Remove Element
- 使用动态库时的配置步骤(windows) - vs2008
- 结合自己情况聊下iOS学习建议