Task Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5550    Accepted Submission(s): 1786

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
  1.  
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
  1.  
Case 1: Yes

Case 2: Yes

 

Author
allenlowesy
 

Source

field=problem&key=2010+ACM-ICPC+Multi-University+Training+Contest%A3%A813%A3%A9%A1%AA%A1%AAHost+by+UESTC&source=1&searchmode=source">2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC 

题意:有M个机器。有N个任务。

每一个任务必须在Si
或者以后開始做,在Ei 或者之前完毕,完毕任务必须处理Pi 个时间单位。

当中,每一个任务能够在随意(空暇)机器上工作。每一个机器的同一时刻仅仅能工作一个任务,

每一个任务在同一时刻仅仅能被一个机器工作,并且任务做到一半能够打断,拿去其它机器做。

问:是否能在规定时间内把任务做完。

思路:这题最大流最基本的就是建图。 
刚開始学最大流的仅仅会模板的我果断不知道怎么建图。參考大神思路: 
直接把0作为源点。最小的開始时间到最大的结束时间作为任务,0到任务的权值为机器个数;
从最大结束时间到它乘以2作为天数,每一个任务连范围内的全部时间点,权值为1, 
最大结束时间乘以2加1作为汇点。每一个时间点到汇点权值为机器个数。判满流。
Dinic 

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. #include<queue>
  5. using namespace std;
  6. #define M 1100
  7. #define inf 0x3f3f3f3f
  8. int head[M],dis[M];
  9. int n,m,t,cnt;
  10. struct node{
  11. int u,v,next,w;
  12. }mp[M*M];
  13. void add(int u,int v,int w){//邻接表
  14. mp[cnt].u=u;
  15. mp[cnt].v=v;
  16. mp[cnt].w=w;
  17. mp[cnt].next=head[u];
  18. head[u]=cnt++;
  19. mp[cnt].u=v;//反向边
  20. mp[cnt].v=u;
  21. mp[cnt].w=0;
  22. mp[cnt].next=head[v];
  23. head[v]=cnt++;
  24. }
  25. int bfs(){
  26. int s=0;
  27. memset(dis,-1,sizeof(dis));
  28. queue <int> q;
  29. while(!q.empty()) q.pop();
  30. dis[s]=0;
  31. q.push(s);
  32. while(!q.empty()){
  33. s=q.front();
  34. q.pop();
  35. for(int i=head[s];i!=-1;i=mp[i].next){
  36. int v=mp[i].v;
  37. if(dis[v]==-1&&mp[i].w){
  38. dis[v]=dis[s]+1;
  39. if(v==t) return 1;//假设搜到汇点直接结束函数
  40. q.push(v);
  41. }
  42. }
  43. }
  44. return 0;
  45. }
  46. int dfs(int s,int low){
  47. if(s==t) return low;
  48. int a,i,ans=0;
  49. for(i=head[s];i!=-1;i=mp[i].next){
  50. int v=mp[i].v;
  51. if(mp[i].w && dis[v]==dis[s]+1 && (a=dfs(v,min(low,mp[i].w))) ){
  52. mp[i].w-=a;
  53. mp[i^1].w+=a;//反向边
  54. ans+=a;//这两行是速度优化 ,我试了非常多次。写的话200多MS,
  55. if(ans==low) break;//不写的话就超时
  56. }
  57. }
  58. return ans;
  59. }
  60. int main(){
  61. int T,i,j,t1,t2,sum,cas=1;
  62. int s[505],e[505],q[505];
  63. scanf("%d",&T);
  64. while(T--){
  65. sum=0; t1=inf; t2=-1;
  66. scanf("%d%d",&n,&m);
  67. for(i=1;i<=n;i++){
  68. scanf("%d%d%d",&q[i],&s[i],&e[i]);
  69. t1=min(s[i],t1);
  70. t2=max(e[i],t2);
  71. sum+=q[i];
  72. }
  73. memset(head,-1,sizeof(head));
  74. cnt=0; t=t2*2+1;//t为超级汇点
  75. for(i=t1;i<=t2;i++)
  76. add(0,i,m);//超级源点0到每一个任务连线。每条线权值为机器个数
  77. for(i=1;i<=n;i++){
  78. for(j=s[i];j<=e[i];j++){
  79. add(j,j+t2,1);//每一个任务和任务相关的每一天权值设为1
  80. add(j+t2,t2*2+1,m);//每一天到汇点t2*2+1,设置成机器个数m。事实上这我也试了好多次。
  81. // 设置成1,或者q每一个任务的持续的时间数,都能够AC,,好像不影响= =+
  82. }
  83. }
  84. int ans=0,k;
  85. while(bfs()){
  86. while(k=dfs(0,inf))
  87. ans+=k;
  88. }
  89. if(sum<=ans)//能完毕的话
  90. printf("Case %d: Yes\n\n",cas++);
  91. else printf("Case %d: No\n\n",cas++);
  92. }
  93. return 0;
  94. }

hdu 3572 Task Schedule(最大流&amp;&amp;建图经典&amp;&amp;dinic)的更多相关文章

  1. HDU 3572 Task Schedule (最大流)

    C - Task Schedule Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  2. hdu 3572 Task Schedule (dinic算法)

    pid=3572">Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. HDU 3572 Task Schedule(拆点+最大流dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. hdu 3572 Task Schedule(最大流)2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC

    题意: 告诉我们有m个任务和k个机器.第i个任务需要ci天完成,最早从第ai天开始,最晚在第bi天结束.每台机器每天可以执行一个任务.问,是否可以将所有的任务都按时完成? 输入: 首行输入一个整数t, ...

  5. hdu 3572 Task Schedule【 最大流 】

    求出最大流,再判断是否满流 先不理解为什么要这样建图 后来看了这一篇题解 http://blog.csdn.net/u012350533/article/details/12361003 把0看做源点 ...

  6. hdu 3572 Task Schedule

    Task Schedule 题意:有N个任务,M台机器.每一个任务给S,P,E分别表示该任务的(最早开始)开始时间,持续时间和(最晚)结束时间:问每一个任务是否能在预定的时间区间内完成: 注:每一个任 ...

  7. 解题报告:hdu 3572 Task Schedule(当前弧优化Dinic算法)

    Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...

  8. HDU 3572 Task Schedule(ISAP模板&amp;&amp;最大流问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3572 题意:m台机器.须要做n个任务. 第i个任务.你须要使用机器Pi天,且这个任务要在[Si  , ...

  9. hdu 3572 Task Schedule (Dinic模板)

    Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...

随机推荐

  1. UTF-8 与 BIG-5 转码

    BIG-5 轉 UTF-8 若要將一個文字檔從 BIG-5 編碼轉換為 UTF-8 編碼,可以執行: iconv -f BIG-5 -t UTF-8 big5.txt > utf8.txt 其中 ...

  2. 【20181019T3】比特战争【最小生成树思想】

    题面 [错解] Hmm不可做啊 要不按b排个序? 然后并查集瞎搞,刷刷刷过了样例 然后大样例大了几万倍 出了组小数据,Successful Hack 弃疗 水过10分 [正解] 用占领的边将顶点连起来 ...

  3. 【BFS】【并查集】【Tarjan】【LCA】Gym - 101173H - Hangar Hurdles

    给你一张地图,给你q次询问,每次问你从A点到B点,最大能移动多大的箱子. 把每个点所能容纳的最大箱子求出来(BFS,八连通,一开始将所有边界点和障碍点入队).然后从大到小排序.然后用并查集将相邻(四联 ...

  4. AIM Tech Round (Div. 1) D. Birthday 数学 暴力

    D. Birthday 题目连接: http://www.codeforces.com/contest/623/problem/D Description A MIPT student named M ...

  5. CentOS 6.9下iptables通过raw表实现日志输出和调试

    说明:iptables调试的最好方式应该是输出日志了.并且iptables有个raw的表,优先级别最好,且调试时针对icmp协议(ping)进行,那么日志输出就是整条链路串起来输出的,非常的清晰. 前 ...

  6. 给XC2440开发板烧写程序的N种方式

    转:http://blog.chinaunix.net/uid-22030783-id-3420080.html 给XC2440开发板烧写程序非常灵活,总结起来有这么几种方式:   空片烧写(flas ...

  7. opencv Mat 像素操作

    1 cv::Mat cv::Mat是一个n维矩阵类,声明在<opencv2/core/core.hpp>中.   class CV_EXPORTS Mat { public: //a lo ...

  8. vim配置python开发环境(转)

    安装 因为许多Unix衍生系统已经预装了Vim,我们首先要确认编辑器是否成功安装: vim --version 如果已经安装了,你应该看到类似下面的文字: VIM - Vi IMproved 7.3 ...

  9. 《深入理解Java虚拟机》笔记4

    垃圾回收器是垃圾回收算法的实现,Java虚拟机的设计者为了 获取最大的性价比,也在不断改进中.硬件在不断变化,多核 的普及,基于单核的收集器应该已经没有太大意义了.Java7中 又新增了g1收集器,没 ...

  10. [Android Pro] Android中全局Application的onCreate多次调用问题

    一般来说Application的onCreate方法只会执行一次, 如果应用中采用多进程方式,oncreate方法会执行多次,根据不同的进程名字进行不同的初始化, 就是在application中多添加 ...