题目链接

题意:

有M个机器,N个任务

对第i个任务,需要在[Si,Ei]这段时间内恰有Pi天被process

每天最多有M个机器同时工作

每一天,一个任务若被process,那么它恰占用一个机器。

题解:建图,设一个超级源点S编号为0,超级汇点T编号为1001,编号[1,500]表示任务[1,500],编号[501,100]表示时间[1,500] (为与原题对应,建边时用500作为偏移量)。

每一天最多同时加工M个任务,故每一天向超级汇点连一条容量为M的边 以满足此不等关系。

每个任务最多需要Pi天,那么超级汇点向每个任务连一条容量为Pi的边。

每个任务要在[Si,Ei]中选时间进行process,那么,从任务i向[Si,Ei]中的每一天都分别连一条容量为1的边。

最后,如果跑得的最大流==sigma(Pi),那么就是"Yes"了

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; namespace FastIO
{
const static int MX=1e6;
bool IOerror=;
char nc()
{
static char buf[MX],*p1=buf+MX,*pend=buf+MX;
if(p1==pend)
{
p1=buf;
pend=buf+fread(buf,,MX,stdin);
if(pend==p1)
{
IOerror=;
return -;
}
}
return *p1++;
}
inline bool blank(char ch)
{
return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
}
inline int read(int& x)
{
char ch;
while(blank(ch=nc()));
if(IOerror) return ;
for(x=ch-''; (ch=nc())>=''&&ch<=''; x=x*+ch-''); //printf("%d===\n",x);
return ;
}
}
using namespace FastIO; const int N=;
const int M=;
const int INF=0x3f3f3f3f; struct Edge
{
int to,next;
int flow,cap; //根据情况设定变量类型
Edge(){}
Edge(int _to,int _next,int _cap,int _flow)
{
to=_to,next=_next,cap=_cap,flow=_flow;
}
};
Edge edge[M<<];
int head[N],tot;
int cur[N];
int d[N]; void init()
{
memset(head,-,sizeof(head));
tot=;
}
inline void addedge(int u,int v,int cap)
{
edge[tot]=Edge(v,head[u],cap,);
head[u]=tot++;
edge[tot]=Edge(u,head[v],,);
head[v]=tot++;
}
int bfs(int s,int t)
{
memset(d,-,sizeof(d));
queue<int> Q;
Q.push(s),d[s]=;
while(!Q.empty())
{
int u=Q.front();Q.pop();
for(int i=head[u];~i;i=edge[i].next)
{
int v=edge[i].to;
if(d[v]==-&&edge[i].cap>edge[i].flow)
{
d[v]=d[u]+;
if(v==t) return ;
Q.push(v);
}
}
}
return ~d[t];
}
int dfs(int s,int t,int a)
{
if(s==t||a==) return a;
int flow=,df;
// for(int& i=cur[s];~i;i=edge[i].next)
for(int i=head[s];~i;i=edge[i].next)
{
int v=edge[i].to;
// if(d[v]==d[s]+1 &&
// (df=dfs(v,t,min(a,edge[i].cap-edge[i].flow))>0)) //这种写法 hdu6214 TLE
if(d[v]==d[s]+&&edge[i].cap>edge[i].flow
&&(df=dfs(v,t,min(a,edge[i].cap-edge[i].flow)))>)
{
edge[i].flow+=df;
edge[i^].flow-=df;
flow+=df;
a-=df;
if(a==) break;
}
}
if(flow==) d[s]=-;
return flow;
}
int dinic(int s,int t)
{
int ret=;
while(bfs(s,t))
{
// memcpy(cur,head,sizeof(cur));
ret+=dfs(s,t,INF);
}
return ret;
} int main()
{
int T,kase=;
int s=,t=;
read(T);
while(T--)
{
int n,m; // n表示任务总数,m表示点容量
int sum=; // sum表示实际所需总时间
read(n),read(m);
init(); for(int i=; i<=n; i++)
{
int l,p,r;
read(p),read(l),read(r);
sum+=p;
addedge(s,i,p);
for(int j=l; j<=r; j++)
addedge(i,j+,);
}
for(int j=; j<=; j++)
addedge(j+,t,m); printf("Case %d: ",++kase);
if(dinic(s,t)==sum)
puts("Yes");
else puts("No");
puts("");
}
}

hdu 3572 : Task Schedule (网络流)的更多相关文章

  1. hdu 3572 Task Schedule 网络流

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

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

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

  5. hdu 3572 Task Schedule

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

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

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

    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. 阶段3 1.Mybatis_12.Mybatis注解开发_7 Mybatis注解开发一对多的查询配置

    一对多的配置,一个用户对应多个账户 需要在Accout里面增加根据用户的uid查询的方法 在user里面指定子一对多的查询配置 换行显示 测试 把这里注销掉.测试延迟加载,代码注释掉后,延迟加载就没有 ...

  2. 小姐姐带你一起学:如何用Python实现7种机器学习算法(附代码)

    小姐姐带你一起学:如何用Python实现7种机器学习算法(附代码) Python 被称为是最接近 AI 的语言.最近一位名叫Anna-Lena Popkes的小姐姐在GitHub上分享了自己如何使用P ...

  3. Servlet 三种创建方式

    servlet 是运行在 Web 服务器(tomcat)中的小型 Java 程序(即:服务器端的小应用程序) (其实就是一个java类,只不过不用再new了).servlet 通常通过 HTTP(超文 ...

  4. python字符串的学习计划

    python字符串有14小节内容, 计划7天学完吧(不知道能完成不) 今天依然是在禅道上写用例的一天 禅道上的用例,编写的时候比较方便 修改维护的时候,有点小麻烦(没有在Excel表中容易修改) D5 ...

  5. Django-DRF组件学习-其他学习

    1.认证Authentication 可以在配置文件中配置全局默认的认证方案 REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_ ...

  6. if you wanna the rainbow, you have to deal with the rain.

    bulk. n. 大量 reluctant. adj. 不情愿的 terrorist. n. 恐怖分子 recognition. n. 认出 tout.v. 兜售 conceal.v. 隐藏 dras ...

  7. ThinkPHP目录下面php文件 Access denied. 的问题

    对于这种拒绝访问的报错,从我遇到过的问题总结来讲,可以从几个方向入手: 1. 文件权限. 最容易想到的也是这个 使用命令chmod -R 777 目录名 2. 环境配置.    这个我也是有遇到过的 ...

  8. IDEA 快捷键 (长期更新)

    自动清除无效 import 和 清除无效 import  ctrl+alt+o    

  9. Linux Apache使用CGI

    CGI(Common Gateway Interface,通用网关接口)是网络服务器可以将查询传递到专门的程序中并且在网页上显示结果的标准机制.Apache等服务器默认是支持CGI的,只需要修改一下配 ...

  10. c++ 判断两圆位置关系

    对于两圆的位置一般有五种关系: (1) 外离:两圆的半径之和小于两圆圆心距离 (2) 外切:两圆的半径之和等于两圆圆心距离 (3) 相交:两圆的半径之和大于两圆圆心距离,两圆圆心距离大于两圆半径之差 ...