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
 
给N个任务,M台机器。每个任务有最早才能开始做的时间S,deadline E,和持续工作的时间P。每个任务可以分段进行,但是在同一时刻,一台机器最多只能执行一个任务. 问存不存在可行的工作时间。

由于时间<=500且每个任务都能断断续续的执行,那么我们把每一天时间作为一个节点来用网络流解决该题.
建图: 源点s(编号0), 时间1-500天编号为1到500, N个任务编号为500+1 到500+N, 汇点t(编号501+N).
源点s到每个任务i有边(s, i, Pi)
每一天到汇点有边(j, t, M) (其实这里的每一天不一定真要从1到500,只需要取那些被每个任务覆盖的每一天即可)
如果任务i能在第j天进行,那么有边(i, j, 1) 注意由于一个任务在一天最多只有1台机器执行,所以该边容量为1,不能为INF或M哦.
最后看最大流是否 == 所有任务所需要的总天数.

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int maxn = ;
  5. const int inf = 0x3f3f3f3f;
  6. struct Edge
  7. {
  8. int from,to,cap,flow;
  9. Edge (int f,int t,int c,int fl)
  10. {
  11. from=f,to=t,cap=c,flow=fl;
  12. }
  13. };
  14. struct Dinic
  15. {
  16. int n,m,s,t;
  17. vector <Edge> edge;
  18. vector <int> G[maxn];//存图
  19. bool vis[maxn];//标记每点是否vis过
  20. int cur[maxn];//当前弧优化
  21. int dep[maxn];//标记深度
  22. void init(int n,int s,int t)//初始化
  23. {
  24. this->n=n;this->s=s;this->t=t;
  25. edge.clear();
  26. for (int i=;i<n;++i) G[i].clear();
  27. }
  28. void addedge (int from,int to,int cap)//加边,单向边
  29. {
  30. edge.push_back(Edge(from,to,cap,));
  31. edge.push_back(Edge(to,from,,));
  32. m=edge.size();
  33. G[from].push_back(m-);
  34. G[to].push_back(m-);
  35. }
  36. bool bfs ()
  37. {
  38. queue<int> q;
  39. while (!q.empty()) q.pop();
  40. memset(vis,false,sizeof vis);
  41. vis[s]=true;
  42. dep[s]=;
  43. q.push(s);
  44. while (!q.empty()){
  45. int u=q.front();
  46. //printf("%d\n",u);
  47. q.pop();
  48. for (int i=;i<G[u].size();++i){
  49. Edge e=edge[G[u][i]];
  50. int v=e.to;
  51. if (!vis[v]&&e.cap>e.flow){
  52. vis[v]=true;
  53. dep[v]=dep[u]+;
  54. q.push(v);
  55. }
  56. }
  57. }
  58. return vis[t];
  59. }
  60. int dfs (int x,int mi)
  61. {
  62. if (x==t||mi==) return mi;
  63. int flow=,f;
  64. for (int &i=cur[x];i<G[x].size();++i){
  65. Edge &e=edge[G[x][i]];
  66. int y=e.to;
  67. if (dep[y]==dep[x]+&&(f=dfs(y,min(mi,e.cap-e.flow)))>){
  68. e.flow+=f;
  69. edge[G[x][i]^].flow-=f;
  70. flow+=f;
  71. mi-=f;
  72. if (mi==) break;
  73. }
  74. }
  75. return flow;
  76. }
  77. int max_flow ()
  78. {
  79. int ans = ;
  80. while (bfs()){
  81. memset(cur,,sizeof cur);
  82. ans+=dfs(s,inf);
  83. }
  84. return ans;
  85. }
  86. }dinic;
  87. int full_flow;
  88. int main()
  89. {
  90. int casee = ;
  91. //freopen("de.txt","r",stdin);
  92. int T;scanf("%d",&T);
  93. while (T--){
  94. int n,m;
  95. full_flow = ;
  96. scanf("%d%d",&n,&m);
  97. int src = ,dst = ++n;
  98. dinic.init(++n,src,dst);
  99. bool vis[maxn];
  100. memset(vis,false,sizeof vis);
  101. for (int i=;i<=n;++i){
  102. int p,s,e;
  103. scanf("%d%d%d",&p,&s,&e);
  104. full_flow+=p;
  105. dinic.addedge(src,i+,p);
  106. for (int j=s;j<=e;++j){
  107. vis[j]=true;
  108. dinic.addedge(i+,j,);
  109. }
  110. }
  111. for (int i=;i<maxn;++i){
  112. if (vis[i])
  113. dinic.addedge(i,dst,m);
  114. }
  115. printf("Case %d: ",++casee);
  116. if (dinic.max_flow()==full_flow){//dinic.max_flow()只能跑一遍
  117. printf("Yes\n\n");
  118. }
  119. else
  120. printf("No\n\n");
  121. }
  122. return ;
  123. }

hdu 3572 Task Schedule (Dinic模板)的更多相关文章

  1. hdu 3572 Task Schedule (dinic算法)

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

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

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

  3. 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 ...

  4. HDU 3572 Task Schedule (最大流)

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

  5. hdu 3572 Task Schedule

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

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

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

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

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

  8. hdu 3572 Task Schedule 网络流

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

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

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

随机推荐

  1. APP测试之-网址

    App测试那么多机型怎么搞? http://www.jianshu.com/p/1a9aa2cf0d85 移动App的分类 http://www.jianshu.com/p/01f5db8958d2 ...

  2. Spring CGLlB动态代理

    JDK 动态代理使用起来非常简单,但是它也有一定的局限性,这是因为 JDK 动态代理必须要实现一个或多个接口,如果不希望实现接口,则可以使用 CGLIB 代理. CGLIB(Code Generati ...

  3. LINK : fatal error LNK1561: 必须定义入口点

    转自VC错误:http://www.vcerror.com/?p=1313 问题描述: 错误:LINK : fatal error LNK1561: 必须定义入口点 解决方法: 详细的解决方法可参考V ...

  4. 边缘节点 如何判断CDN的预热任务是否执行完成刷新 路由追踪 近期最少使用算法

    阿里云内容分发网络(Content Delivery Network,简称CDN)是建立并覆盖在承载网之上,由分布在不同区域的边缘节点服务器群组成的分布式网络.阿里云CDN分担源站压力,避免网络拥塞, ...

  5. xshell链接linux出现SSH服务器拒绝了密码 的解决方案

    参考文章:https://blog.csdn.net/weixin_38554662/article/details/80589852 但是需要注意的是,ssh_config文件本来是没有权限修改的, ...

  6. 测开之路四十三:ajax请求

    ajax固定套路 function http(url, data, method, success, fail) { data = method == 'GET' ? data : JSON.stri ...

  7. 关于JS读取DOM对象(标签)的自定义属性

    DOM对象对于js来说,是个很基础的元素,我们写js一般来说,都一定会对它进行操作.我们可以很方便地给它加上自定义的属性,比如: var test = document.getElementById( ...

  8. 2644. 数列 (Standard IO)

    这道题是道数论题,如果想对了的话会很快. 因为这道题实在是没有什么知识点,所以我直接上代码,代码上有很详细的注释: #include<iostream> #include<cstdi ...

  9. 简单DP入门(二) 最长上升子序列及其优化

    最长上升子序列解决问题: 有N个数,求出它最长的上升子序列并输出长度. 在题里不会讲的这么直白,这个算法往往会与其他的算法混在一起使用. 在这篇文章中不会出现其他的例题,为了让大家更好的理解,我只会对 ...

  10. [LeetCode] 196.删除重复的电子邮箱

    编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个. +----+------------------+ | Id | Email | +-- ...