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. IT菜鸟的第2天(输入输出,数据类型,运算符的使用)

    1:输入输出 另一种读写方法: 注释:Console.Write(Line{自动换行})是输入,string xxx = Console.ReadLine();是输出. string :字符串类型   ...

  2. java 接口(上)

    1.接口中的方法都是抽象方法.而普通的抽象类里面不一定都是抽象方法.抽象类中必须有抽象方法,同时也可以有非抽象方法.继承抽象父类的子类中,如果依然有抽象方法,那么这个子类也是抽象类.即只要类中有抽象方 ...

  3. c#匿名类,匿名对象

    何谓匿名类,其实本质和普通定义的类一样,只不过是由系统的编译器来完成的,首先举个例子. 一般情况 //声明一个类,包含贴别多的字段 public class Person() { public str ...

  4. sublime text2 配置代码对齐快捷键

    menu under Preferences → Key Bindings – User [{"keys": ["ctrl+shift+r"], "c ...

  5. sudo命令使用的几个场景

    在linux系统下,普通用户无法直接执行root用户权限下的命令,如果想让普通用户执行只有root用户才能执行的操作命令.下面罗列下经常使用sudo命令的几个场景: 1.用户无权限执行root命令普通 ...

  6. RPM方式编译升级centos内核

    [root@iZ2893wjzgyZ ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org [root@iZ2893wjzgyZ ...

  7. win7 远程桌面关机

    在任务管理器中, 打开运行窗口, 执行 shutdown -s 命令, 将在30秒后关闭win7, 如果需要更快, 加上 -t 10 参数 关于 shutdown 的命令行说明: C:\Users\R ...

  8. DEDECMS之十 修改织梦链和文章的默认来源及作者

    今天在用织梦搭网站的时候,发现了两个问题,一个就是最新的dedecms5.7系统中默认会加上“织梦链”这一个链接组,织梦的做法是可以理解的, 但是给别人做网站,这些链接是不能要的,所以在数据库,模板文 ...

  9. There is no ‘Animation’ attached to the “Player” game object

    There is no ‘Animation’ attached to the “Player” game object 在照着龚老师的Unity3D投篮游戏视频教程练习时,遇到这个错误提示. 我知道 ...

  10. 【转】Sql Server参数化查询之where in和like实现详解

    转载至:http://www.cnblogs.com/lzrabbit/archive/2012/04/22/2465313.html 文章导读 拼SQL实现where in查询 使用CHARINDE ...