题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=3572

题意:m台机器。须要做n个任务。

第i个任务。你须要使用机器Pi天,且这个任务要在[Si  ,  Ei]区间内完毕才有效。

对于一个任务,仅仅能由一个机器来完毕。一个机器同一时间仅仅能做一个任务。

当然,一个任务能够分成几段不连续的时间来完毕。问,是否能做完所有任务。

题意非常清晰。也就是推断是否是满流。

对于网络流问题,模板大家都有,关键在于怎样建图(详见资料

思路:今天问了龙哥,对建图有了一定的了解,建图分为4部分,源点->X集合->Y集合->汇点(X、Y类似于二分匹配图)。确定这个4个部分后,就是找这个4个部分的关系,也就是构建容量网络

这题的X集合能够当做任务编号。Y集合当做天数(第几天)

某任务->某一天。若是能够在这天做任务。建一条容量为1的边,最后,把每天到汇点再建一条边容量M(表示每台机器最多工作M个任务)即最大容量是M。

以第二组实例作图(真挫。。)

模板应用的是ISAP(可当做模板)。个人非常倾向ISAP

Accepted 2292 KB 62 ms C++
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <math.h>
  7. #include <queue>
  8. #define init(a) memset(a,0,sizeof(a))
  9. #define PI acos(-1,0)
  10. using namespace std;
  11. const int maxn = 1100;
  12. const int maxm = 400000;
  13. #define lson left, m, id<<1
  14. #define rson m+1, right, id<<1|1
  15. #define min(a,b) (a>b)?b:a
  16. #define max(a,b) (a>b)?a:b
  17. #define MAX INT_MAX
  18.  
  19. int head[maxn], sum, bnum;
  20. int dis[maxn]; //残量网络中节点 i 到汇点 t 的最短距离
  21. int num[maxn]; //和 t 的最短距离等于 i 的节点数量
  22. int cur[maxn]; //当前弧下标
  23. int pre[maxn]; //可增广路上的上一条弧的编号
  24. struct node
  25. {
  26. int v, cap;
  27. int next;
  28. }edge[maxm];
  29. void add(int u, int v, int cap)//加边,储存地图
  30. {
  31. edge[bnum].v=v;
  32. edge[bnum].cap=cap;
  33. edge[bnum].next=head[u];
  34. head[u]=bnum++;
  35.  
  36. edge[bnum].v = u;
  37. edge[bnum].cap=0;
  38. edge[bnum].next=head[v];
  39. head[v] = bnum++;
  40. }
  41. void BFS(int source,int sink)//预处理。利用反向BFS。更新dis数组
  42. {
  43. queue<int>q;
  44. while(q.empty()==false) q.pop();
  45. memset(num,0,sizeof(num));
  46. memset(dis,-1,sizeof(dis));
  47. q.push(sink);
  48. dis[sink]=0;
  49. num[0]=1;
  50. while(!q.empty())
  51. {
  52. int u=q.front();
  53. q.pop();
  54. for(int i=head[u];i!=-1;i=edge[i].next)
  55. {
  56. int v=edge[i].v;
  57. if(dis[v] == -1)
  58. {
  59. dis[v] = dis[u] + 1;//找同意弧
  60. num[dis[v]]++;
  61. q.push(v);
  62. }
  63. }
  64. }
  65. }
  66. int ISAP(int source,int sink,int n)//n为残量网络中的节点到汇点的最大距离,通常节点的个数。即上限
  67. {
  68. memcpy(cur,head,sizeof(cur));
  69. int flow=0, u = pre[source] = source;
  70. BFS( source,sink);//更新dis数组
  71. while( dis[source] < n )
  72. {
  73. if(u == sink)
  74. {
  75. int df = MAX, pos;
  76. for(int i = source;i != sink;i = edge[cur[i]].v)//追踪增广路路径。最小残量df
  77. {
  78. if(df > edge[cur[i]].cap)
  79. {
  80. df = edge[cur[i]].cap;
  81. pos = i;
  82. }
  83. }
  84. for(int i = source;i != sink;i = edge[cur[i]].v) //更新流量
  85. {
  86. edge[cur[i]].cap -= df;
  87. edge[cur[i]^1].cap += df;
  88. }
  89. flow += df;
  90. u = pos;
  91. }
  92. int st;
  93. for(st = cur[u];st != -1;st = edge[st].next)// 从当前弧開始查找同意弧
  94. {
  95. if(dis[edge[st].v] + 1 == dis[u] && edge[st].cap)//找到同意弧跳出
  96. {
  97. break;
  98. }
  99. }
  100. if(st != -1)
  101. {
  102. cur[u] = st;
  103. pre[edge[st].v] = u;
  104. u = edge[st].v;
  105. }
  106. else
  107. {
  108. if( (--num[dis[u]])==0 ) break;//GAP优化,出现断层结束
  109. int mind = n;
  110. for(int id = head[u];id != -1;id = edge[id].next)//retreat操作:更新 dis 数组
  111. {
  112. if(mind > dis[edge[id].v] && edge[id].cap)
  113. {
  114. cur[u] = id;//改动标号的同一时候改动当前弧
  115. mind = dis[edge[id].v];
  116. }
  117. }
  118. dis[u] = mind+1;
  119. num[dis[u]]++;
  120. if(u!=source)
  121. u = pre[u];// 回溯继续寻找同意弧
  122. }
  123. }
  124. return flow;
  125. }
  126. void initt()
  127. {
  128. memset(head,-1,sizeof(head));
  129. bnum=0;
  130. }
  131.  
  132. int main()
  133. {
  134. int T, N,M,a,b,c;
  135. int maa, sum, source, sink, n;
  136. scanf("%d", &T);
  137. for (int cas = 1; cas <= T; ++cas)
  138. {
  139. initt();
  140. sum = 0; source = 0; maa = 0;
  141. scanf("%d%d", &N, &M);
  142. for (int i = 1; i <= N; i++)
  143. {
  144. scanf("%d%d%d", &a, &b, &c);
  145. sum += a;
  146.  
  147. if(c > maa) maa = c;
  148.  
  149. add(source, i, a);
  150.  
  151. for (int j = b; j <= c; ++j)
  152. {
  153. add(i, N + j, 1);
  154. }
  155. }
  156. sink = N + maa + 1;
  157. n = sink;
  158. for (int i = 1; i <= maa; ++i)
  159. {
  160. add(N + i, sink, M);
  161. }
  162.  
  163. printf("Case %d: ", cas);
  164. int ans = ISAP(source, sink, n);
  165. if(ans==sum)
  166. puts("Yes");
  167. else
  168. puts("No");
  169. cout<<endl;
  170. }
  171. return 0;
  172. }

HDU 3572 Task Schedule(ISAP模板&amp;&amp;最大流问题)的更多相关文章

  1. hdu 3572 Task Schedule (Dinic模板)

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

  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 (最大流)

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

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

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

  5. hdu 3572 Task Schedule

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

  6. hdu 3572 Task Schedule(最大流&amp;&amp;建图经典&amp;&amp;dinic)

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

  7. hdu 3572 Task Schedule 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3572 Our geometry princess XMM has stoped her study i ...

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

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

  9. 图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)

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

随机推荐

  1. spring boot打包文件后,报错\No such file or directory

    现象: 一段代码: ClassLoader loader = XXXUtil.class.getClassLoader(); String jsFileName = loader.getResourc ...

  2. Spring Cloud (10) Hystrix-监控面板

    Hystrix DashBoard 断路器是根据一段时间窗内的请求状况来判断并操作断路器的打开和关闭状态的.Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界 ...

  3. Android项目实战_手机安全卫士home界面

    # 安全卫士主页面# ###1.GridView控件 1.与ListView的使用方式差不多,也要使用数据适配器,通过设置android:numColumns控制显示几列 2.通过指定android: ...

  4. DeltaFish 小组成员及个人博客地址

    艾寅中  http://www.cnblogs.com/aiyz 陈志锴  http://www.cnblogs.com/chenzhikai 李   鑫  http://www.cnblogs.co ...

  5. node 第三方包学习

    时间格式化 moment var moment = require('moment'); moment().format();

  6. html5——颜色

    CSS2 1.opacity,可以设置透明度,但是父盒子设置了透明度会影响子盒子 CC3 1.transparent属性,但是不可改变透明值 2.rgba():r--red g--green b--b ...

  7. spring+spring MVC+mybatis 框架搭建

    1.新建一个javaWeb工程Test,创建时记得勾选web.xml文件. 2.导入需要的jar包,Mybatis所有的jar,spring所有的jar,mysql驱动包. 这里mybatis和spr ...

  8. Codeforces_731F_(前缀和)

    F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. Linux cat 命令

    cat命令是linux下的一个文本输出命令,通常是用于观看某个文件的内容的:cat主要有三大功能:1.一次显示整个文件.$ cat   filename2.从键盘创建一个文件.$ cat  >  ...

  10. Ubuntu | Flask + Gunicorn + Nginx 部署服务器环境

    现在我们手里有一个准备发布的项目,那么如何将他上传到你的服务器,并让外网访问呢? 前提: 1. 安装了Python环境 apt-get install python-dev 2. 安装Flask pi ...