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. Alpha总结

    一.预期计划 1.时间:11月7日--11月17日 2.小组分工 角色:程序员.美工.文档.测试 这个阶段以编码为主,每个组员参与编码,同时各自根据自己擅长的方面主要负责一个部分. 项目编码工作分工: ...

  2. Java的native方法

    一. 什么是Native Method   简单地讲,一个Native Method就是一个java调用非java代码的接口.一个Native Method是这样一个java的方法:该方法的实现由非j ...

  3. linux启动和关闭

    startup,startup mount,startup nomount之间的区别: STARTUP NOMOUNT选项:(读初始化参数文件,启动实例)STARTUP NOMOUNT选项启动实例,但 ...

  4. session超时时间设置方法

    session超时时间设置方法 由于session值之前没有设置,以至于刚登录的网站,不到一分钟就超时了,总结了一下,原来是session过期的原因,以下是设置session时间的3个方法: 1. 在 ...

  5. [ubuntu]--vim命令

  6. 各大就业网站对web前端的就业要求

    今日与女神有约,在[web前端学习部落22群]有直播公开课,喜欢的朋友赶紧加入吧!随着高等教育的普及,高校毕业生的人数每年都以极快的速度增长,数据显示,2016年,高校毕业生多达765万人,比2015 ...

  7. FluentData(微型ORM)

    using FluentData; using System; using System.Collections.Generic; using System.Linq; using System.Te ...

  8. python环境变量自动配置脚本(setx使用)

    前言 setx不是windows系统自带的工具,需要到微软官网下载,但是有的系统也会自带.(是官方提供的,可放心食用) set和setx都可以用来配置环境变量.他们的不同点在于,set只是临时的修改环 ...

  9. 一个请求在Struts2框架中的处理流程

    1.客户端向Servlet容器发起一个请求,将请求封装为HttpServletRequest对象. 2.HttpServletRequest首先经过web.xml中配置的struts2的过滤器,以及s ...

  10. Asp.net导出Excel续章(自定义合并单元格,非Office组件)

    结合上次写的导出Excel方法,这次上头要求我将列头进行一下合并 以前的效果: 改进后的效果: 在上篇文章中写到了Excel的导出方法,这次为了避免在生产环境中使用Office组件,服务器各种权限配置 ...