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. 问题--feed列表有新闻重复的问题

    1. 经常有运营反应,客户端展示的feed列表有重复的问题. 重复问题分为两种,一种是两条新闻标题类似,另一种是两条新闻标题是完全相同. (1)标题类似 原来过滤的逻辑,是两个标题完全相等,才认为两条 ...

  2. 【GWAS文献】基于GWAS与群体进化分析挖掘大豆相关基因

    Resequencing 302 wild and cultivated accessions identifies genes related to domestication and improv ...

  3. 学习OpenStack之(6):Neutron 深入学习之 OVS + GRE 之 Compute node 篇

    0.环境 硬件环境见上一篇博客:学习OpenStack之(5):在Mac上部署Juno版本OpenStack 四节点环境 OpenStack网络配置:一个tenant, 2个虚机 Type drive ...

  4. 【Network】高性能 UDP 应该怎么做?

    参考资料: EPOLL-UDP-GOLANG golang udp epoll - Google 搜索 go - golang: working with multiple client/server ...

  5. python的一道面试题 __call__ 的使用.

    class Person: def __init__(self): self.age = 1 def __call__(self, *args, **kwargs): print 'age', sel ...

  6. mongodb的查询语句学习摘要

    看了些资料,对应只需要知道怎么查询和使用mongodb的我来说,这些足够啦. 左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * fr ...

  7. 常用语句if,for,while

    一.变量赋值 a = 3 b = a a = 5 print a,b 5,3   变量命名规则:   1.显式 2.nums_of_alex_gf = 19 3.NumsOfAlexGf = 2 4. ...

  8. 【leetcode】Perfect Squares (#279)

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  9. ThinkPHP 表单提交操作成功后执行JS操作如何刷新父页面或关闭当前页等操作

    ThinkPHP 表单提交操作成功后执行JS操作如何刷新父页面或关闭当前页等操作 .操作成功后刷新父页面 $this->assign('jumpUrl', "javascript:wi ...

  10. a pity

    机会只眷顾有准备且自信的人,此生谨记. ——Charles Hsu 2014-09-04