题意:

题目意思:

给出 N 件任务和 M台机器, 这N件任务都一个限制: 必须在 [S,E] 之间完成, 而且完成的时间不能超过 P.

一台机器每天只能做意见任务, 不过庆幸的是: 任务是可以拆分的, 比如一件任务要3天完成, 那么你就可以将呀拆分

成3份. 现在问: 在所有机器慢负荷运转的情况下, 如何分配这些任务使得在最后的期限时, 所有任务都能完成.

解题 :

仔细分析下题目不难想到是个网络流模型, 问题就是求源点的流是否能够全部流到汇点. 关键在于构图. 我们选取一个

超级源点和一个超级汇点, 一开始把源点指向所有的任务, 边权就是完成这件任务需要的天数, 然后按照完成这件任务

的时间区间, 将任务分成 E-S+1份, 意思就是在这几天中每天都可以完成这件任务的一份.这样, 就可以在任务和能够完

成它的这些天之间连边, 边权为1, 因为每次只能做一份, 最后在所有的天和汇点之间连边, 边权为M, 表示每一天, M台

机器可以完成M份工作:

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 92 2 2 1 3 1 2 2

Sample Output

    
Case 1: YesCase 2: Yes

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
struct node
{int u, v, w, next;
} edge[200000] ;
int head[200000], pre[200000], cur[200000];
int dis[200000],gap[20000],aug[20000];
int s,e,T,cnt;
void add(int u,int v,int w)
{edge[cnt].u=u;edge[cnt].v=v;edge[cnt].w=w;edge[cnt].next=head[u];head[u]=cnt++;edge[cnt].u=v;edge[cnt].v=u;edge[cnt].w=0;edge[cnt].next=head[v];head[v]=cnt++;
}
int SAP()
{int max_flow = 0, v, u = s;int id, mindis;aug[s] = INF;pre[s] = -1;memset(dis, 0, sizeof(dis));memset(gap, 0, sizeof(gap));gap[0] = T; // 我觉得这一句要不要都行,因为dis[e]始终为0for (int i = 0; i <=T; ++i){   // 初始化当前弧为第一条弧cur[i] = head[i];}while (dis[s] < T){bool flag = false;if (u == e){max_flow += aug[e];for (v = pre[e]; v != -1; v = pre[v]) // 路径回溯更新残留网络{id = cur[v];edge[id].w -= aug[e];edge[id^1].w += aug[e];aug[v] -= aug[e]; // 修改可增广量,以后会用到if (edge[id].w == 0) u = v; // 不回退到源点,仅回退到容量为0的弧的弧尾}}for (id = cur[u]; id != -1; id = edge[id].next){   // 从当前弧开始查找允许弧v = edge[id].v;if (edge[id].w > 0 && dis[u] == dis[v] + 1) // 找到允许弧{flag = true;pre[v] = u;cur[u] = id;aug[v] = min(aug[u], edge[id].w);u = v;break;}}if (flag == false){if (--gap[dis[u]] == 0) break; /* gap优化,层次树出现断层则结束算法 */mindis = T;cur[u] = head[u];for (id = head[u]; id != -1; id = edge[id].next){v = edge[id].v;if (edge[id].w > 0 && dis[v] < mindis){mindis = dis[v];cur[u] = id; // 修改标号的同时修改当前弧}}dis[u] = mindis + 1;gap[dis[u]]++;if (u != s) u = pre[u]; // 回溯继续寻找允许弧}}return max_flow;
}
int main()
{int t,Case,n,m;int pi,si,ei;scanf("%d",&t);for(Case=1;Case<=t;Case++){cnt=0;int maxl=-1;int day=0;s=0;memset(head,-1,sizeof(head));scanf("%d %d",&n,&m);for(int i=1;i<=n;i++){scanf("%d %d %d",&pi,&si,&ei);day+=pi;maxl=max(maxl,ei);add(s,i,pi);                 //源点到每个任务for(int j=si;j<=ei;j++)add(i,j+n,1);             //任务到起始和结束天数之间}e=maxl+n+1;T=e+1;for(int i=1;i<=maxl;i++)add(i+n,e,m);          //天数到汇点 权值是每天有m台机器if(SAP()==day)printf("Case %d: Yes\n\n",Case);elseprintf("Case %d: No\n\n",Case);}return 0;
}

hdu 3572 Task Schedule IPSA 最大流相关推荐

  1. hdu 3572 Task Schedule 网络流

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

  2. HDU 3572 Task Schedule

    传送门 作业调度,这道题还真没想到能用网络流....乍一看跟背包问题差不多. 有N个作业,M个机器,每个作业给你一个耗费时间(时间段)以及最早开始时间和最晚完成时间(这两个是时间点),单位是天.一个作 ...

  3. 题解报告:hdu 4907 Task schedule

    Problem Description 有一台机器,并且给你这台机器的工作表,工作表上有n个任务,机器在ti时间执行第i个任务,1秒即可完成1个任务. 有m个询问,每个询问有一个数字q,表示如果在q时 ...

  4. HDU 4907 BestCoder3_1 Task schedule

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

  5. light task schedule的定时任务实现源码解析

    light task schedule(以下简称lts)的任务调度是在jobTracker中实现的. 以下关于任务队列的数据存储以mysql为例子. jobTracker中进行调度的任务需要jobCl ...

  6. TASK SCHEDULE(任务计划)服务无法运行 解决方案

    Q:TASK SCHEDULE(任务计划)服务无法运行? A:因为Event Log服务没有打开,所以TASK SCHEDULE服务也打不开 转载于:https://www.cnblogs.com/w ...

  7. LTS 轻量级分布式任务调度框架(Light Task Schedule) - 推酷

    LTS 轻量级分布式任务调度框架(Light Task Schedule) - 推酷

  8. hdu 3572(最大流)

    建图:把每个任务和每一天都看做一个点,添加源点和汇点.源点与每个任务之间连一条边,容量为完成该任务所需处理次数.若第i个任务可以在Si至Ei天处理,则由该任务向这些天分别连一条边,容量为1,表示此任务 ...

  9. Task Schedule

    http://acm.hdu.edu.cn/showproblem.php?pid=3572 题意:给N个任务,M台机器.每个任务有最早才能开始做的时间S,deadline E,和持续工作的时间P.每 ...

最新文章

  1. apex图表使用饼图居中_ppt图表技巧:如何制作美观简洁的百分比饼图
  2. [Caffe]:关于Eltwise layer
  3. Linux基础配置和查看命令帮助
  4. 74cms 注入exp
  5. c语言中,x-y,'105',ab,7f8那个是正确的,C语言程序设计_第三章 数据.ppt
  6. 翻译:A DSL in 5 Languages(五种语言的DSL)
  7. 磁力mysql搜索_多功能搜索 搜索系统安装 小说 电影 磁力
  8. UML建模系列文章总结 [转]
  9. 实战Spring Boot 2.0系列(一) - 使用Gradle构建Docker镜像
  10. camera(24)---camera 客观测试 Imatest教程--噪声测试
  11. PHP中的PDO详解
  12. 以京东为代表电商平台成中华老字号销售增速最快渠道
  13. 非常使用的mongodb的聚合函数(使用SpringDataMongoDb)
  14. 5E7月3号服务器在维护,5E对战平台西南服务器上线!全新S2赛季即将开启
  15. SocksCap64全局代理设置教程
  16. python学生信息管理系统 实验报告_Python学生信息管理系统的开发
  17. ROS | 服务通信的编程实现
  18. 可以下载全球气象资料的网站
  19. html怎么在图中加字,用HTML代码在图片上加字
  20. 在Mac上运行.exe文件

热门文章

  1. 40XXX队技术员交接事项(4):电子版IADC与井史录入
  2. Onboarding
  3. mac最高权限删文件
  4. U盘删除的文件如何恢复?简单步骤介绍
  5. win7造字(不全好用)
  6. python keyboard 键盘自动控制库
  7. HMC5883 电子罗盘
  8. 一级建造师资格考试合格标准
  9. php mvc多层依赖注入,演示依赖注入,MVC,路由案例 2019年10月12日 08:00
  10. Elasticsearch 7.X SpringBoot 使用 ElasticsearchRestTemplate 操作 ES