博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 3572 Task Schedule
阅读量:4695 次
发布时间:2019-06-09

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

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. 

InputOn 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. 
OutputFor 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

24 31 3 5 1 1 42 3 73 5 92 22 1 31 2 2

Sample Output

Case 1: Yes   Case 2: Yes 题意: 有m台机器,n个任务,每个任务需要p天完成,任务开始日期s,结束日期t,中间可以间断,但是每天每台机器只能进行一件任务。问能否按要求完成任务。 解法: 网络流 从源点向每一个任务节点连接一条容量为p的边,从每一个任务节点向每天连接一个容量为1的边,日期的节点向汇点连接一条容量为5的边,跑一遍最大流看流量是否为每件任务每台机器需要的时间和。 代码:
#include 
using namespace std;int ii=0;#define N 1010#define M 320010#define ll int#define inf 100000000inline ll Max(ll a,ll b) { return a>b?a:b;}inline ll Min(ll a,ll b){ return a
Q; while(!Q.empty()) Q.pop(); Q.push(Start); dis[Start]=0;vis[Start]=1; while(!Q.empty()){ int u=Q.front(); Q.pop(); // cout<
<
E.flow){ vis[E.to]=1; dis[E.to]=dis[u]+1; if (E.to==End) return true; Q.push(E.to); } } } return false;}int DFS(int x,int a,int End){ if (x==End||a==0) return a; int flow=0,f; for (int &i=cur[x];i!=-1;i=edge[i].nex){ Edge &E=edge[i]; if (dis[x]+1==dis[E.to]&&(f=DFS(E.to,Min(a,E.cap-E.flow),End))>0){ E.flow+=f; edge[i^1].flow-=f; flow+=f; a-=f; if (a==0) break; } } return flow;}int Maxflow(int Start,int End){ int flow=0; while(BFS(Start,End)){ memcpy(cur,head,sizeof(head)); flow+=DFS(Start,inf,End); } return flow;}void deal(){ init(); ii++; int n,m; scanf("%d%d",&n,&m); int start,end; start=0; int p,s,t; int ans=0; int maxt=0; for (int i=1;i<=n;i++){ scanf("%d%d%d",&p,&s,&t); addedge(0,i,p); ans+=p; for (int j=s;j<=t;j++){ addedge(i,j+n,1); } if (t>maxt) maxt=t; } for (int i=1;i<=maxt;i++){ addedge(n+i,n+maxt+1,m); } int flow=Maxflow(0,n+maxt+1); printf("Case %d: ",ii);// cout<<"ans: "<
<

  

转载于:https://www.cnblogs.com/xfww/p/7717746.html

你可能感兴趣的文章
SQL 优化经验总结34条
查看>>
开源 视频会议 收藏
查看>>
核心J2EE模式 - 截取过滤器
查看>>
.net开源CMS
查看>>
JdbcTemplate
查看>>
第一次使用maven记录
查看>>
SharePoint服务器端对象模型 之 使用CAML进展数据查询
查看>>
Building Tablet PC Applications ROB JARRETT
查看>>
Adobe® Reader®.插件开发
查看>>
【POJ 3461】Oulipo
查看>>
Alpha 冲刺 (5/10)
查看>>
使用Siege进行WEB压力测试
查看>>
斑马为什么有条纹?
查看>>
android多层树形结构列表学习笔记
查看>>
Android_去掉EditText控件周围橙色高亮区域
查看>>
《构建之法》第一、二、十六章阅读笔记
查看>>
arrow:让Python的日期与时间变的更好
查看>>
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>
Java并发编程
查看>>
Git Stash用法
查看>>