hdu 3572 Task Schedule (Dinic模板)
Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
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.
Print a blank line after each test case.
由于时间<=500且每个任务都能断断续续的执行,那么我们把每一天时间作为一个节点来用网络流解决该题.
建图: 源点s(编号0), 时间1-500天编号为1到500, N个任务编号为500+1 到500+N, 汇点t(编号501+N).
源点s到每个任务i有边(s, i, Pi)
每一天到汇点有边(j, t, M) (其实这里的每一天不一定真要从1到500,只需要取那些被每个任务覆盖的每一天即可)
如果任务i能在第j天进行,那么有边(i, j, 1) 注意由于一个任务在一天最多只有1台机器执行,所以该边容量为1,不能为INF或M哦.
最后看最大流是否 == 所有任务所需要的总天数.
#include <bits/stdc++.h> using namespace std;
const int maxn = ;
const int inf = 0x3f3f3f3f;
struct Edge
{
int from,to,cap,flow;
Edge (int f,int t,int c,int fl)
{
from=f,to=t,cap=c,flow=fl;
}
};
struct Dinic
{
int n,m,s,t;
vector <Edge> edge;
vector <int> G[maxn];//存图
bool vis[maxn];//标记每点是否vis过
int cur[maxn];//当前弧优化
int dep[maxn];//标记深度
void init(int n,int s,int t)//初始化
{
this->n=n;this->s=s;this->t=t;
edge.clear();
for (int i=;i<n;++i) G[i].clear();
}
void addedge (int from,int to,int cap)//加边,单向边
{
edge.push_back(Edge(from,to,cap,));
edge.push_back(Edge(to,from,,));
m=edge.size();
G[from].push_back(m-);
G[to].push_back(m-);
}
bool bfs ()
{
queue<int> q;
while (!q.empty()) q.pop();
memset(vis,false,sizeof vis);
vis[s]=true;
dep[s]=;
q.push(s);
while (!q.empty()){
int u=q.front();
//printf("%d\n",u);
q.pop();
for (int i=;i<G[u].size();++i){
Edge e=edge[G[u][i]];
int v=e.to;
if (!vis[v]&&e.cap>e.flow){
vis[v]=true;
dep[v]=dep[u]+;
q.push(v);
}
}
}
return vis[t];
}
int dfs (int x,int mi)
{
if (x==t||mi==) return mi;
int flow=,f;
for (int &i=cur[x];i<G[x].size();++i){
Edge &e=edge[G[x][i]];
int y=e.to;
if (dep[y]==dep[x]+&&(f=dfs(y,min(mi,e.cap-e.flow)))>){
e.flow+=f;
edge[G[x][i]^].flow-=f;
flow+=f;
mi-=f;
if (mi==) break;
}
}
return flow;
}
int max_flow ()
{
int ans = ;
while (bfs()){
memset(cur,,sizeof cur);
ans+=dfs(s,inf);
}
return ans;
}
}dinic;
int full_flow;
int main()
{
int casee = ;
//freopen("de.txt","r",stdin);
int T;scanf("%d",&T);
while (T--){
int n,m;
full_flow = ;
scanf("%d%d",&n,&m);
int src = ,dst = ++n;
dinic.init(++n,src,dst);
bool vis[maxn];
memset(vis,false,sizeof vis);
for (int i=;i<=n;++i){
int p,s,e;
scanf("%d%d%d",&p,&s,&e);
full_flow+=p;
dinic.addedge(src,i+,p);
for (int j=s;j<=e;++j){
vis[j]=true;
dinic.addedge(i+,j,);
}
}
for (int i=;i<maxn;++i){
if (vis[i])
dinic.addedge(i,dst,m);
}
printf("Case %d: ",++casee);
if (dinic.max_flow()==full_flow){//dinic.max_flow()只能跑一遍
printf("Yes\n\n");
}
else
printf("No\n\n");
}
return ;
}
hdu 3572 Task Schedule (Dinic模板)的更多相关文章
- hdu 3572 Task Schedule (dinic算法)
pid=3572">Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 3572 Task Schedule(拆点+最大流dinic)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- hdu 3572 Task Schedule(最大流&&建图经典&&dinic)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 3572 Task Schedule (最大流)
C - Task Schedule Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 3572 Task Schedule
Task Schedule 题意:有N个任务,M台机器.每一个任务给S,P,E分别表示该任务的(最早开始)开始时间,持续时间和(最晚)结束时间:问每一个任务是否能在预定的时间区间内完成: 注:每一个任 ...
- 解题报告:hdu 3572 Task Schedule(当前弧优化Dinic算法)
Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...
- HDU 3572 Task Schedule(ISAP模板&&最大流问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3572 题意:m台机器.须要做n个任务. 第i个任务.你须要使用机器Pi天,且这个任务要在[Si , ...
- hdu 3572 Task Schedule 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3572 Our geometry princess XMM has stoped her study i ...
- 图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)
Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...
随机推荐
- 谷歌已经对Android的开源严防死守
上周,沸沸扬扬的Android垄断案把Google又一次推向了风口浪尖,在这次的垄断案中,Google被欧盟起诉赔偿50亿美元,被起诉的其中一个原因是Google对外宣称Android是开放的,但其实 ...
- HDU 6034 Balala Power! —— Multi-University Training 1
Talented Mr.Tang has nn strings consisting of only lower case characters. He wants to charge them wi ...
- MacOS Catalina 导致bash命令失效的一些总结
欢天喜地的升级了最新的OS后,第一个发现bash失效的是使用pod命令出现: -bash: pod: command not found 这个不会导致cocoapods无法正常使用,可以使用绝对路径里 ...
- NGINX配置之二: nginx location proxy_pass 后面的url 加与不加/的区别.
这里我们分4种情况讨论 这里我们请求的网站为:192.168.1.123:80/static/a.html 整个配置文件是 server{ port 80, server name 192.168.1 ...
- js另存为、打印、属性、加入收藏、关闭等代码
js打开代码 <input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开> &l ...
- HBase–RegionServer宕机恢复原理
Region Server宕机总述 HBase一个很大的特色是扩展性极其友好,可以通过简单地加机器实现集群规模的线性扩展,而且机器的配置并不需要太好,通过大量廉价机器代替价格昂贵的高性能机器.但也正因 ...
- luogu P4183 Cow at Large P (暴力吊打点分治)(内有时间复杂度证明)
题面 贝茜被农民们逼进了一个偏僻的农场.农场可视为一棵有N个结点的树,结点分别编号为 1,2,-,N .每个叶子结点都是出入口.开始时,每个出入口都可以放一个农民(也可以不放).每个时刻,贝茜和农民都 ...
- HDU 4366 Successor( DFS序+ 线段树 )
Successor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDFS文件的基本操作
HDFS文件的基本操作: package wjn; import java.io.BufferedInputStream; import java.io.BufferedReader; import ...
- Introduction to Object-Oriented JavaScript 转载自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
Introduction to Object-Oriented JavaScript IN THIS ARTICLE JavaScript review Object-oriented program ...