Task Schedule

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

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
 

题目链接:HDU 3572

拆点的最大流判断是否满流的题目,点怎么拆呢?从源点S连向每一个任务i一条容量为p的边,说明每一个任务一开始要p个流量流入,然后每一个任务i向时间点[s,e]连一条容量为1的边,说明一个任务只能同时在一个时间点被工作,即不能同时既在时间点A上加工又在时间点B上加工,然后每一个时间点向T连一条容量为m个边,说明一个时间点只能最多同时有m个机器在工作。最后你就是要判断从S流出的$n*p$个流量能否全部流入T中就好了

空间复杂度大概是$(500+500^2+500)*2$条边,$500+500$个点,原本只会最辣鸡的FF想低空卡过这题,然而被无限TLE教做人,查查题解又膜膜dinic,发现dinic也容易理解,分层的意义就是减少没有用的搜索,因为增广一定是从最小距离距离近的到最小距离远的,那么那些d[v]!=d[u]+1的点就可以被忽略掉了

代码:

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int N=1010;
const int M=251000+7;
struct edge
{
int to,nxt;
int cap;
};
edge E[M<<1];
int head[N],tot,d[N]; void add(int s,int t,int cap)
{
E[tot].to=t;
E[tot].cap=cap;
E[tot].nxt=head[s];
head[s]=tot++; E[tot].to=s;
E[tot].cap=0;
E[tot].nxt=head[t];
head[t]=tot++;
}
void init()
{
CLR(head,-1);
tot=0;
}
int bfs(int s,int t)
{
CLR(d,-1);
d[s]=0;
queue<int>Q;
Q.push(s);
while (!Q.empty())
{
int now=Q.front();
Q.pop();
for (int i=head[now]; ~i; i=E[i].nxt)
{
int v=E[i].to;
if(d[v]==-1&&E[i].cap>0)
{
d[v]=d[now]+1;
if(v==t)
return 1;
Q.push(v);
}
}
}
return d[t]!=-1;
}
int dfs(int s,int t,int f)
{
if(s==t||!f)
return f;
int r=0;
for (int i=head[s]; ~i; i=E[i].nxt)
{
int v=E[i].to;
if(d[v]==d[s]+1&&E[i].cap)
{
int d=dfs(v,t,min(f,E[i].cap));
if(d>0)
{
E[i].cap-=d;
E[i^1].cap+=d;
r+=d;
f-=d;
if(!f)
break;
}
}
}
if(!r)
d[s]=INF;
return r;
}
int dinic(int s,int t)
{
int r=0;
while (bfs(s,t))
r+=dfs(s,t,INF);
return r;
}
int main(void)
{
int tcase,p,s,e,i,j,n,m;
scanf("%d",&tcase);
for (int q=1; q<=tcase; ++q)
{
init();
scanf("%d%d",&n,&m);
int S=0;
int tl=INF,tr=-INF;
int sump=0;
for (i=1; i<=n; ++i)
{
scanf("%d%d%d",&p,&s,&e);
add(S,i,p);
sump+=p; if(s<tl)
tl=s;
if(e>tr)
tr=e; for (j=s; j<=e; ++j)
add(i,n+j,1);
}
int T=n+tr+1;
for (i=tl; i<=tr; ++i)
add(n+i,T,m);
printf("Case %d: %s\n\n",q,dinic(S,T)==sump?"Yes":"No");
}
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算法)

    pid=3572">Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. HDU 3572 Task Schedule (最大流)

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

  4. 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 ...

  5. hdu 3572 Task Schedule

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

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

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

  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(最大流判断满流)

    https://vjudge.net/problem/HDU-3572 题意: 有N个作业和M台机器,每个作业都有一个持续时间P,工作的日期为S~E.作业可以断断续续的在不同机器上做,每台机器每次只可 ...

  9. hdu 3572 Task Schedule【 最大流 】

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

随机推荐

  1. linux常用命令-帮助命令man,whatis,apropos,info,help

    man 命令 man 配置文件,注意这里只需要写文件名称就可以了,不能写文件的绝对路径 man既可以查看命令的帮助信息也可以查看配置文件的帮助信息,如果内容太多,可以输入"/内容" ...

  2. python %s深入解析

    默认我们通常用字符串填充它 'Keep %s, and you will aways make %' % ('moving', 'it') 如果你就此止步,那就错过了一些神乎其技的用法 比如: arr ...

  3. 模仿mybatis,用jdk proxy实现接口

    在mybatis中,我们都只需要定义一个mapper接口,但并不需要对它进行任务实现.只要有对就的mapper.xml文件就可以访问数据库.那么,没有接口的访问是如何实现的呢. 答案就是JDK pro ...

  4. java冒泡排序

    public class BubbleSort { public static void main(String[] args) { int score[] = {1,4,5,7,2,3,9,0,6, ...

  5. Java基础之反射和动态代理

    1,反射是依赖于Class对象,然后根据Class对象,去操作该类的资源的.Class对象是发射的基石! 问题1:人这类事物用什么表示?汽车这类事物用什么表示>计算机文件用什么表示?有如此多的事 ...

  6. AngularJS Bootstrap

    AngularJS 的首选样式表是 Bootstrap. 可以在 AngularJS 应用中加入 Twitter Bootstrap,你可以在你的 <head>元素中添加如下代码: < ...

  7. 基于命令行编译打包phonegap for android应用 分类: Android Phonegap 2015-05-10 10:33 73人阅读 评论(0) 收藏

    也许你习惯了使用Eclipse编译和打包Android应用.不过,对于使用html5+js开发的phonegap应用,本文建议你抛弃Eclipse,改为使用命令行模式,绝对的快速和方便. 一直以来,E ...

  8. AutoMapper搬运工之自定义类型转换

    前言 最近还挺忙,还有点累,一直都没更新了,实在是懒呀.正题之前先说点别的,最近公司要扩张了,需要大量开发,领导说推荐有钱可以拿,如此好机会,我就趁机做个广告.ShippingRen.com招募.NE ...

  9. Winform实现用多线程、百度地图API解析某公司的物理地址

    前言 作为一个很挫的C#新手总喜欢自己写点儿不着边际的东西,本人是个新手加菜鸟,写B/S的,工作中,任务完成了,空闲下来,总想继续学点儿什么,由此触发了本篇文章了.个人一直认为,.NET中,C/S所要 ...

  10. Visual Studio 插件的开发(转)

    起因 在做项目的时候,经常需要根据表结构create一些实体类,写多了,实在是觉得无趣,于是就琢磨着做个代码生成工具.当然现在有很多现成的,拿来用就好,可是总想自己弄个出来玩玩,一来是当初用DataS ...