Task Schedule

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 

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台机器。第i个任务,从si天,到ei天内处理pi遍结束。每次机器只能处理一个任务。
问能否完成所有的任务。
思路:
最大流解决。建立超级源点和汇点。源点和每个任务建边,权值为处理的次数pi,表示完成
该任务需要的ci次数。对于每一个任务,若能在si到ei间,那么从第i个任务建边到si到ei天 ,
权值为1,表示每一天能够处理一次。从每一天建边到汇点,权值为机器数量,
表示每天能够处理m个任务。如果汇点得到的值等于源点流出的值,那么yes。
 

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
const int MAXM = ;
struct node{
int to;
int val;
int next;
}edge[MAXM*];
int x[MAXN],y[MAXN],z[MAXN];
int pre[MAXN],vis[MAXN],ind,k,n,m,S,T;
void add(int x,int y,int z){
edge[ind].to = y;
edge[ind].val = z;
edge[ind].next = pre[x];
pre[x] = ind ++;
}
bool bfs(){
queue<int>q;
memset(vis,-,sizeof(vis));
vis[S] = ;
q.push(S);
while(!q.empty()){
int tp = q.front();
q.pop();
for(int i = pre[tp]; i != -; i = edge[i].next){
int t = edge[i].to;
if(vis[t] == - && edge[i].val){
vis[t] = vis[tp] + ;
q.push(t);
}
}
}
return vis[T] != -;
}
int dfs(int rt,int low){
int used = ;
if(rt == T){
return low;
}
for(int i = pre[rt]; i != - && used < low; i = edge[i].next){
int t = edge[i].to;
if(vis[t] == vis[rt] + && edge[i].val){
int b = dfs(t,min(low-used,edge[i].val));
edge[i].val -= b;
edge[i^].val += b;
used += b;
}
}
if(used == ){
vis[rt] = -;
}
return used;
}
int main(){
int t,ff = ;
scanf("%d",&t);
while(t--){
scanf("%d%d",&m,&k);
ind = ;
memset(pre,-,sizeof(pre));
n = ;
ll all = ;
for(int i = ; i <= m; i++){
int fx,fy,fz;
scanf("%d%d%d",&fx,&fy,&fz);
x[i] = fy;
y[i] = fx;
z[i] = fz;
n = max(n,z[i]);
all += y[i];
}
for(int i = ; i <= m; i++){
for(int j = x[i]; j <= z[i]; j++){
add(i,j+m,),add(j+m,i,);
}
}
S = ,T = m + n + ;
for(int i = ; i <= m; i++){
add(S,i,y[i]),add(i,S,);
}
for(int i = ; i <= n; i++){
add(i+m,T,k),add(T,i+m,);
}
ll ans = ;
while(bfs()){
while(){
ll a = dfs(S,INF);
if(!a)break;
ans += a;
}
}
//cout<<S<<" "<<T<<endl;
printf("Case %d: ",++ff);
if(ans == all){
printf("Yes\n");
}
else {
printf("No\n");
}
printf("\n");
}
return ;
}

hdu3572 最大流的更多相关文章

  1. [hdu3572]最大流(dinic)

    题意:有m台机器,n个任务,每个任务需要在第si~ei天之间,且需要pi天才能完成,每台机器每天只能做一个任务,不同机器每天不能做相同任务,判断所有任务是否可以做完. 思路: 把影响答案的对象提取出来 ...

  2. 【最大流】【HDU3572】Task Schedule

    题意: 有N个事件,M台机器.事件有开始时间,持续时间,要在结束时间之前完成,问是否能完成所有事件? 非自己思考出来的 建图:把每个任务和每一天都看做一个点,添加源点和汇点.源点与每个任务之间连一条边 ...

  3. hdu3572 任务分配/最大流量推论全流

    意甲冠军:将n分配的任务m机.到的每个任务需要的天数(如果没有持续的日常),并能做到在哪些天任务.询问是否有计划. 典型的任务(X)----日(Y)一半的最大流量,(因为这个任务是天之间的关系)处理器 ...

  4. hdu-3572 Task Schedule---最大流判断满流+dinic算法

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

  5. hdu3572 任务分配/最大流判断满流

    题意:将n个任务分配为m个机器,给每个任务需要的天数(无需每天连续),和可以在哪些天去做该任务,求是否存在方案. 典型的任务(X)----天(Y)二分最大流,(因为这里任务是与天的关系)处理器控制流量 ...

  6. HDU3572:Task Schedule【最大流】

    上了一天课 心塞塞的 果然像刘老师那么说 如果你有挂科+4级没过 那基本上是WF队 题目大意:有时间补吧 思路:给每个任务向每个时间点连边容量为1 每个时间点向汇点连边 容量为机器的个数 源点向每个任 ...

  7. HDU3572 Task Schedule(最大流+构图思维)

    题意: 有N个任务M个机器,给每个任务i完成所花费的时间Pi且每个任务要在第Si天后开始,在第Ei天前结束,保证任务在(S,E)之间一定能完成. 每个机器在一天里只能运行一个任务,一个任务可以在中途更 ...

  8. 最大流任务调度——hdu3572二分图建图

    很简单的任务调度模板题 把一个工作完成一天的量当做是边 /* 任务调度问题最大流 因为两个任务之间是没有关系的,两天之间也是没有关系的 所以抽象成二分图 任务i在天数[si,ei]之间都连一条双向边, ...

  9. HDU3572 Task Schedule 【最大流】

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

随机推荐

  1. 【Unity3d】Ray射线初探-射线的原理及用法

    http://www.xiaobao1993.com/231.html 射线是一个无穷的线,开始于origin并沿着direction方向. 当射线碰到物体后.它就会停止发射. 在屏幕中拉一个CUBE ...

  2. 为什么 Java 不提供无符号类型呢?

    网上查资料,无意中找到一个java写的开源论坛,用的人还挺多 http://jforum.net/ 查MD5,了解到 Java getBytes方法详解(字符集问题) http://liushilan ...

  3. code blocks 如何实现一键代码格式化

    问题:code blocks 如何实现一键代码格式化 解答:直接右键,选择format use ASstyle

  4. ORACLE临时表总结(转载)

    转载地址:http://www.cnblogs.com/kerrycode/p/3285936.html 临时表概念 临时表就是用来暂时保存临时数据(亦或叫中间数据)的一个数据库对象,它和普通表有些类 ...

  5. HTML 学习笔记 CSS3 (背景)

    CSS3对于background做了一些修改,最明显的一个就是采用设置多背景,不但添加了4个新属性,并且还对目前的属性进行了调整增强. 1.多个背景图片 在CSS3里面 你可以在一个标签元素里应用多个 ...

  6. 使用 JavaScript File API 实现文件上传

    概述 以往对于基于浏览器的应用而言,访问本地文件都是一件头疼的事情.虽然伴随着 Web 2.0 应用技术的不断发展,JavaScript 正在扮演越来越重要的角色,但是出于安全性的考虑,JavaScr ...

  7. cell与cell之间的间距问题,以及section跟随屏幕滑动而滑动问题

    苹果在cell与cell之间默认没有间距,这样有时候不能满足我们界面要求,所以我们就需要将cell设置为分组模式(也就是每组一行或者多行,分为n组),然后我们就可以在代理中根据自己的需求设计cell之 ...

  8. Java数据类型和变量

    Java中存在2种数据类型,下面我们来详解一下: 基本数据类型: 引用数据类型: 可以用一张表来记录: 基本数据类型 整型 byte:1个字节8位,取值范围为:[-128, 127],直接写值:(by ...

  9. Web API删除JSON格式的文件记录

    Insus.NET的系列Web Api学习文章,这篇算是计划中最后一篇了,删除JSON格式的文件记录.前一篇<Web Api其中的PUT功能演示>http://www.cnblogs.co ...

  10. android源码framework下添加新资源的方法

    编译带有资源的jar包,需要更改frameworks层,方法如下: 一.增加png类型的图片资源 1.将appupdate模块所有用到的png格式图片拷贝到framework/base/core/re ...