pid=3572">Task Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 3412    Accepted Submission(s): 1197

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
 

思路:建一个超级源点0,然后如果工作区间长度为T ,再建立[1,T]个点,源点到每一个点的流量为M(每天仅仅有M台机器工作)。接着。把对应的工作日向后平移T 天,每一个工作日到对应的[1,T]的流量为1,到终点的流量也为1.

最后求最大流是否大于等于总总工作量就是了。

#include"stdio.h"
#include"string.h"
#include"queue"
using namespace std;
#define N 1005
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
const int inf=0x7ffffff;
int cnt,n,m,t;
int head[N],q[N],dis[N];
struct node
{
int u,v,w,next;
}map[N*N];
void add(int u,int v,int w)
{
map[cnt].u=u;
map[cnt].v=v;
map[cnt].w=w;
map[cnt].next=head[u];
head[u]=cnt++;
map[cnt].u=v;
map[cnt].v=u;
map[cnt].w=0;
map[cnt].next=head[v];
head[v]=cnt++;
}
int bfs()
{
int i,u,v,t1,t2;
memset(dis,0,sizeof(dis));
u=t1=t2=0;
dis[u]=1;
q[t1++]=u;
while(t2<t1)
{
u=q[t2++];
for(i=head[u];i!=-1;i=map[i].next)
{
v=map[i].v;
if(map[i].w&&!dis[v])
{
dis[v]=dis[u]+1;
if(v==t)
return 1;
q[t1++]=v;
}
}
}
return 0;
}
int dfs(int s,int lim)
{
int i,tmp,v,cost=0;
if(s==t)
return lim;
for(i=head[s];i!=-1;i=map[i].next)
{
v=map[i].v;
if(map[i].w&&dis[s]==dis[v]-1)
{
tmp=dfs(v,min(lim-cost,map[i].w));
if(tmp>0)
{
map[i].w-=tmp;
map[i^1].w+=tmp;
cost+=tmp;
if(cost==lim)
break;
}
else
dis[v]=-1;
}
}
return cost;
}
int dinic()
{
int ans=0,s=0;
while(bfs())
ans+=dfs(s,inf); //printf("%d\n",ans);
return ans;
}
int main()
{
int i,j,T,sum,t1,t2,cas=1;
int s[505],e[505],p[505];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
t1=N;t2=0;
sum=0;
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&p[i],&s[i],&e[i]);
t1=min(t1,s[i]);
t2=max(t2,e[i]);
sum+=p[i];
}
cnt=0;
memset(head,-1,sizeof(head));
for(i=t1;i<=t2;i++) //超级源点到一般源点的流量
{
add(0,i,m);
}
for(i=1;i<=n;i++)
{
for(j=s[i];j<=e[i];j++)
{
add(j,j+t2,1);
add(j+t2,2*t2,1);
}
}
t=t2*2;
if(sum<=dinic())
printf("Case %d: Yes\n\n",cas++);
else
printf("Case %d: No\n\n",cas++);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

hdu 3572 Task Schedule (dinic算法)的更多相关文章

  1. hdu 3572 Task Schedule (Dinic模板)

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

  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 网络流

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

  5. HDU 3572 Task Schedule (最大流)

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

  6. hdu 3572 Task Schedule

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

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

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

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

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

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

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

随机推荐

  1. android &quot;Missing type parameter&quot; 错误

    近期在做android应该的时候出现这个问题,分析了一下日志,发现是在gosn解析的时候会出现,并且出现的时候非常诡异.于是去网上找相关资料. 发现这个问题还是比較常见的,原来是公布版本号和非正式公布 ...

  2. Android至ViewPager添加切换动画——使用属性动画

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/44200623 ViewPager作为Android最经常使用的的组件之中的一个.相 ...

  3. 修ecshop品牌筛选以LOGO图片形式显示

    如何实现商品列表页属性筛选区品牌筛选以LOGO形式展示,最模板总结ecshop/'>ecshop教程入下: 1.修改 category.php 文件,将(大概215行) $sql = " ...

  4. 促销R语言应用性能

    1.       绩效评估 时间的确定 R测量时间是在最简单的方式提供是system.time性能. system.time(expr, gcFirst=TRUE) 这个函数会在不减少程序执行性能的情 ...

  5. VS2010关于error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏

    前段时间自己的系统一直在安装更新.今天突然打开VS2010当运行的时候一直出现error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏这种错误.然后就百度 解决的方法: 1.项目\属 ...

  6. 二十7天 春雨滋润着无形 —Spring依赖注入

    6月11日,明确."夏条绿已密,朱萼缀明鲜.炎炎日正午,灼灼火俱燃." IT人习惯把详细的事物加工成的形状一致的类.正是这种一致,加上合适的规范.才干彰显对象筋道的牙感和bean清 ...

  7. PageRank算法MapReduce实现

    如果你现在需要计算网页的排名只有4一:数据如下面的: baidu 10.00 google,sina,nefu google 10.00 baidu sina 10.00 google nefu 10 ...

  8. Android 反编译(一,apktool+smail2java)

    一:解压缩(获取图片等资源) 对于apk中丰富的资源,假设我们在练习的时候须要引用某些apk中的资源文件时,最简单的办法使用解压缩工具对apk进行解压缩,然后在对应的文件夹下查找须要的资源文件. 二: ...

  9. jQuery来源学习笔记:扩展的实用功能

    // 扩展的实用功能 jQuery.extend({ // http://www.w3school.com.cn/jquery/core_noconflict.asp // 释放$的 jQuery 控 ...

  10. 【原创】纯OO:从设计到编码写一个FlappyBird (五)

    第四部分请点这里 本文将实现DrawBoard. 如前文所述,Obstacle类和Bing类仅仅提供给DrawBoard必要的信息,如何绘制则完全委托给了DrawBoard,也就是说游戏关键类的细节和 ...