博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3572 最大流
阅读量:5264 次
发布时间:2019-06-14

本文共 3391 字,大约阅读时间需要 11 分钟。

Task Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 8610    Accepted Submission(s): 2636

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.
 

 

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.
 

 

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.
 

 

Sample Input
2
4 3
1 3 5
1 1 4
2 3 7
3 5 9
2 2
2 1 3
1 2 2
 

 

Sample Output
Case 1: Yes
Case 2: Yes
 

 

Author
allenlowesy
 

 

Source
 题意:
有n个任务,m台机器,给出每个任务需要耗费的时间以及能做此任务的时间点,每个任务每天只能由一台机器做,一台机器每天只能做一个任务问能否将这些任务做完
输入n,m
输入n行x,y,z表示该任务需要x天,第y天到第z天可以做这个任务
代码:
//从原点连向n个任务容量为该任务需要的时间,n个任务连向500个时间点容量为1(一个任务一天只有一台机器去做),//时间点连向汇点,容量为机器数m(一台机器一天只能做一个任务),求最大流是否等于完成所有任务的天数。#include
#include
#include
#include
#include
using namespace std;const int maxn=2009;const int inf=0x7fffffff;struct Edge{ int from,to,cap,flow; Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f){}};struct Dinic{ int n,m,s,t; vector
edges; vector
g[maxn]; bool vis[maxn]; int d[maxn]; int cur[maxn]; void Init(int n){ this->n=n; for(int i=0;i
q; q.push(s); d[s]=0; vis[s]=1; while(!q.empty()){ int x=q.front();q.pop(); for(int i=0;i<(int)g[x].size();i++){ Edge &e=edges[g[x][i]]; if(!vis[e.to]&&e.cap>e.flow){ vis[e.to]=1; d[e.to]=d[x]+1; q.push(e.to); } } } return vis[t]; } int Dfs(int x,int a){ if(x==t||a==0) return a; int flow=0,f; for(int&i=cur[x];i<(int)g[x].size();i++){ Edge &e=edges[g[x][i]]; if(d[x]+1==d[e.to]&&(f=Dfs(e.to,min(a,e.cap-e.flow)))>0){ e.flow+=f; edges[g[x][i]^1].flow-=f; flow+=f; a-=f; if(a==0) break; } } return flow; } int Maxflow(int s,int t){ this->s=s;this->t=t; int flow=0; while(Bfs()){ memset(cur,0,sizeof(cur)); flow+=Dfs(s,inf); } return flow; }}dc;int main(){ int t,n,m; scanf("%d",&t); for(int cas=1;cas<=t;cas++){ scanf("%d%d",&n,&m); dc.Init(n+502); int x,y,z,sum=0; for(int i=1;i<=n;i++){ scanf("%d%d%d",&x,&y,&z); sum+=x; dc.Addedge(0,i,x); for(int j=y;j<=z;j++) dc.Addedge(i,j+n,1); } for(int i=1;i<=500;i++) dc.Addedge(i+n,501+n,m); printf("Case %d: ",cas); int tmp=dc.Maxflow(0,501+n); if(sum==tmp) printf("Yes\n\n"); else printf("No\n\n"); } return 0;}

 

 

转载于:https://www.cnblogs.com/--ZHIYUAN/p/6928027.html

你可能感兴趣的文章
基于CMMI的敏捷开发过程文档裁剪
查看>>
0925 韩顺平java视频
查看>>
软件需求规格说明书
查看>>
53. Maximum Subarray
查看>>
iOS-程序启动原理和UIApplication
查看>>
SpringMVC入门(二)—— 参数的传递、Controller方法返回值、json数据交互、异常处理、图片上传、拦截器...
查看>>
git的安装
查看>>
mysql 8.0 zip包安装
查看>>
Spring框架系列(三)--Bean的作用域和生命周期
查看>>
springboot + mybatis
查看>>
awk 统计
查看>>
CSS min-height 属性
查看>>
SDN第一次作业
查看>>
模板设计模式的应用
查看>>
【井字游戏】做一款回忆童年的游戏
查看>>
高性能的异步爬虫
查看>>
数据结构(二):栈
查看>>
实训第五天
查看>>
平台维护流程
查看>>
SQL (FMDB)
查看>>