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 ...
随机推荐
- Python3解leetcode Binary Tree PathsAdd Digits
问题描述: Given a non-negative integer num, repeatedly add all its digits until the result has only one ...
- Vue的使用总结(2)
1.Vue 中 class 和 style 的绑定 在 Vue 中,可以通过数据绑定来操作元素的 class 列表和内联样式,操作 class 和 style 是用 v-bind 来绑定的.在将 v- ...
- javascript中new关键字详解
和其他高级语言一样 javascript 中也有 new 运算符,我们知道 new 运算符是用来实例化一个类,从而在内存中分配一个实例对象. 但在 javascript 中,万物皆对象,为什么还要通过 ...
- Cent OS (一)Cents OS的基本安装
1.实验环境: VMware Workstation Pro 14 Pro Cent OS 7 系列. 2. 镜像地址传送门: 阿里云开源镜像站:http://mirrors.aliyun.com ...
- linux设备驱动第一篇:设备驱动程序简介
首先,我们知道驱动是内核的一部分,那么驱动在内核中到底扮演了什么角色呢? 设备驱动程序在内核中的角色:他们是一个个独立的“黑盒子”,使某个特定的硬件响应一个定义良好的内部编程接口,这些接口完全隐藏了设 ...
- linux: 如何查看端口占用?
查看端口占用 $: netstat -anp | grep 8888 tcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN 13404/python3 tcp 0 1 172 ...
- ASP.NET MVC学习系列(二)-WebAPI请求 转载https://www.cnblogs.com/babycool/p/3922738.html
继续接着上文 ASP.NET MVC学习系列(一)-WebAPI初探 来看看对于一般前台页面发起的get和post请求,我们在Web API中要如何来处理. 这里我使用Jquery 来发起异步请求实现 ...
- VUX中selector组件数据错误,value-map不能正常转换接口数据
项目中有个地方需要用到下拉框,使用VUX的selector组件,使用value-map属性进行接口数据转换未成功,出来的还是原数据 看了又看也没写错呀,字段什么的都是复制上去的,去网上查了也没查到怎么 ...
- HTML的head头和标题
HTML中Head头 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- lua脚本分解字符串
--local str = "文字45 文字 789 文们adsd45 文字 wowo 文字 文字 wowo我们 wowo456 wiwo 465我们 456sdf 45 45我们adsd4 ...