Task Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5550    Accepted Submission(s): 1786

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

 

Author
allenlowesy
 

Source

field=problem&key=2010+ACM-ICPC+Multi-University+Training+Contest%A3%A813%A3%A9%A1%AA%A1%AAHost+by+UESTC&source=1&searchmode=source">2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC 

题意:有M个机器。有N个任务。

每一个任务必须在Si
或者以后開始做,在Ei 或者之前完毕,完毕任务必须处理Pi 个时间单位。

当中,每一个任务能够在随意(空暇)机器上工作。每一个机器的同一时刻仅仅能工作一个任务,

每一个任务在同一时刻仅仅能被一个机器工作,并且任务做到一半能够打断,拿去其它机器做。

问:是否能在规定时间内把任务做完。

思路:这题最大流最基本的就是建图。 
刚開始学最大流的仅仅会模板的我果断不知道怎么建图。參考大神思路: 
直接把0作为源点。最小的開始时间到最大的结束时间作为任务,0到任务的权值为机器个数;
从最大结束时间到它乘以2作为天数,每一个任务连范围内的全部时间点,权值为1, 
最大结束时间乘以2加1作为汇点。每一个时间点到汇点权值为机器个数。判满流。
Dinic 

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
#define M 1100
#define inf 0x3f3f3f3f
int head[M],dis[M];
int n,m,t,cnt;
struct node{
int u,v,next,w;
}mp[M*M];
void add(int u,int v,int w){//邻接表
mp[cnt].u=u;
mp[cnt].v=v;
mp[cnt].w=w;
mp[cnt].next=head[u];
head[u]=cnt++;
mp[cnt].u=v;//反向边
mp[cnt].v=u;
mp[cnt].w=0;
mp[cnt].next=head[v];
head[v]=cnt++;
}
int bfs(){
int s=0;
memset(dis,-1,sizeof(dis));
queue <int> q;
while(!q.empty()) q.pop();
dis[s]=0;
q.push(s);
while(!q.empty()){
s=q.front();
q.pop();
for(int i=head[s];i!=-1;i=mp[i].next){
int v=mp[i].v;
if(dis[v]==-1&&mp[i].w){
dis[v]=dis[s]+1;
if(v==t) return 1;//假设搜到汇点直接结束函数
q.push(v);
}
}
}
return 0;
}
int dfs(int s,int low){
if(s==t) return low;
int a,i,ans=0;
for(i=head[s];i!=-1;i=mp[i].next){
int v=mp[i].v;
if(mp[i].w && dis[v]==dis[s]+1 && (a=dfs(v,min(low,mp[i].w))) ){
mp[i].w-=a;
mp[i^1].w+=a;//反向边
ans+=a;//这两行是速度优化 ,我试了非常多次。写的话200多MS,
if(ans==low) break;//不写的话就超时
}
}
return ans;
}
int main(){
int T,i,j,t1,t2,sum,cas=1;
int s[505],e[505],q[505];
scanf("%d",&T);
while(T--){
sum=0; t1=inf; t2=-1;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
scanf("%d%d%d",&q[i],&s[i],&e[i]);
t1=min(s[i],t1);
t2=max(e[i],t2);
sum+=q[i];
}
memset(head,-1,sizeof(head));
cnt=0; t=t2*2+1;//t为超级汇点
for(i=t1;i<=t2;i++)
add(0,i,m);//超级源点0到每一个任务连线。每条线权值为机器个数
for(i=1;i<=n;i++){
for(j=s[i];j<=e[i];j++){
add(j,j+t2,1);//每一个任务和任务相关的每一天权值设为1
add(j+t2,t2*2+1,m);//每一天到汇点t2*2+1,设置成机器个数m。事实上这我也试了好多次。
// 设置成1,或者q每一个任务的持续的时间数,都能够AC,,好像不影响= =+
}
}
int ans=0,k;
while(bfs()){
while(k=dfs(0,inf))
ans+=k;
}
if(sum<=ans)//能完毕的话
printf("Case %d: Yes\n\n",cas++);
else printf("Case %d: No\n\n",cas++);
}
return 0;
}

hdu 3572 Task Schedule(最大流&amp;&amp;建图经典&amp;&amp;dinic)的更多相关文章

  1. HDU 3572 Task Schedule (最大流)

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

  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(拆点+最大流dinic)

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

  4. hdu 3572 Task Schedule(最大流)2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC

    题意: 告诉我们有m个任务和k个机器.第i个任务需要ci天完成,最早从第ai天开始,最晚在第bi天结束.每台机器每天可以执行一个任务.问,是否可以将所有的任务都按时完成? 输入: 首行输入一个整数t, ...

  5. hdu 3572 Task Schedule【 最大流 】

    求出最大流,再判断是否满流 先不理解为什么要这样建图 后来看了这一篇题解 http://blog.csdn.net/u012350533/article/details/12361003 把0看做源点 ...

  6. hdu 3572 Task Schedule

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

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

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

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

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

  9. hdu 3572 Task Schedule (Dinic模板)

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

随机推荐

  1. 深度学习应用系列(三)| autokeras使用入门

    我们在构建自己的神经网络模型时,往往会基于预编译模型上进行迁移学习.但不同的训练数据.不同的场景下,各个模型表现不一,需要投入大量的精力进行调参,耗费相当多的时间才能得到自己满意的模型. 而谷歌近期推 ...

  2. 【BFS】【余数剪枝】Multiple

    [poj1465]Multiple Time Limit: 1000MS   Memory Limit: 32768K Total Submissions: 7731   Accepted: 1723 ...

  3. bzoj 4602: [Sdoi2016]齿轮

    4602: [Sdoi2016]齿轮 Description 现有一个传动系统,包含了N个组合齿轮和M个链条.每一个链条连接了两个组合齿轮u和v,并提供了一个传动比x  : y.即如果只考虑这两个组合 ...

  4. sql server的sql 语句中的列名包含[]时候,把]替换成]]就可以

    sql server的sql 语句中的列名包含[]时候,把]替换成]]就可以eg: create table p.e_LOG_WebServer ( [BSCFlg] int, ), ) ); sel ...

  5. 可添加头部尾部RecyclerView,很帅哦~

    WrapRecyclerView 是一个可以添加头部和尾部的RecyclerView,并且提供了一个 WrapAdapter, 它可以让你轻松为 RecyclerView 添加头部和尾部.   示例中 ...

  6. 【mysql】mysql中varcher属性最大值能存多长

    1.首先理解varchar(n),n表示什么 MySQL5.0.3之前varchar(n)这里的n表示字节数 MySQL5.0.3之后varchar(n)这里的n表示字符数,比如varchar(200 ...

  7. Express重定向

    var express = require('express'); var app = express(); app.get('/',function(req,res){ res.redirect(' ...

  8. Jquery JS 正确的比较两个数字大小的方法

    if(2 > 10){ alert("不正确!");} 此比较不会是想要的结果:它相当于2 >1,把10的第一位取出来比较. 解决方 法:  if(eval(2) &g ...

  9. java中copy 一个list集合的方法

    java将一个list里的数据转移到另外一个list,可以使用for语句,一次使用add方法,示例如下: ArrayList list1=new ArrayList(); list1.add(&quo ...

  10. OTL调用存储过程/函数及注意事项

    OTL 是 Oracle, Odbc and DB2-CLI Template Library 的缩写,是一个 C++ 编译中操控关系数据库的模板库,它目前几乎支持所有的当前各种主流数据库. OTL  ...