HDU 3572(Task Schedule) ISAP做法
题目链接:传送门
题目大意:有n个任务,m个机器。每个机器最早在 Si 天开始,最晚在 Ei 天结束,需要 Pi 天完成。可以中途换机器做,也可以中途打断不做,过后再做
只要在规定时间内都行。每个机器一天只能处理一个任务。问是否能在规定时间完成。
题目思路:知道是网络流,但是不会建图。
自己建图的时候,想法是 S 与任务建边容量为Pi,然后 T 与机器建边,容量为inf,然后时间就不知道怎么处理了。 卡死在这了。
其实知道 任务,机器,时间这三个条件后完全可以变通一下建图的,但是没有转过弯来。还需要继续努力。
正解: 让 S 与任务连边,容量为Pi,T 与时间连边,容量为机器数,任务和时间连边(从起始时间到结束时间),容量 1。
这样把所有限制条件都利用了起来,最后只需判断 最大流与 sum(Pi) 是否相等。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 1105
#define maxn 500005
typedef pair<int,int> PII;
typedef long long LL; int head[N],cur[N],pre[N],d[N],gap[N];
int n,m,hcnt,S,T,sum;
struct Node{
int to,nxt,v;
Node(){}
Node(int a,int b,int c):to(a),nxt(b),v(c){}
}node[maxn];
inline void add(int x,int y,int v){
node[hcnt]=Node(y,head[x],v);head[x]=hcnt++;
node[hcnt]=Node(x,head[y],);head[y]=hcnt++;
}
bool ISAP(int S,int T,int n){ ///起点,终点,总共点数(加上源汇点)
int ans=,aug=inf,i,flag; ///最大流,可增广流量,.,标记
int u,e,dis; ///当前点,当前可达点
mst(gap,);mst(d,);
for(i=;i<=n;++i) cur[i]=head[i];
u=pre[S]=S;
while(d[S]<n){
flag=;
for(i=cur[u];~i;i=node[i].nxt){
e=node[i].to;
if(node[i].v>&&d[u]==d[e]+){
flag=;
break;
}
}
if(flag){
pre[e]=u;
cur[u]=i;
aug=min(aug,node[i].v);
u=e;
if(u==T){
while(u!=S){
u=pre[u];
node[cur[u]].v-=aug;
node[cur[u]^].v+=aug;
}
u=S;
ans+=aug;
aug=inf;
}
}
else{
if(--gap[d[u]]==)break;
dis=n;
cur[u]=head[u];
for(int i=head[u];~i;i=node[i].nxt){
e=node[i].to;
if(node[i].v>&&d[e]+<dis){
dis=d[e]+;
cur[u]=i;
}
}
d[u]=dis;
++gap[dis];
if(u!=S)
u=pre[u];
}
}
return ans==sum;
}
int main(){
int i,j,group,x,y,v;
scanf("%d",&group);
for(int g=;g<=group;++g){
mst(head,-);hcnt=;
scanf("%d%d",&n,&m);
sum=S=;T=n++;
for(i=;i<=n;++i){
scanf("%d%d%d",&v,&x,&y);
sum+=v;
add(S,i,v);
for(j=x;j<=y;++j)
add(i,n+j,);
}
for(i=;i<=;++i)add(i+n,T,m);
printf("Case %d: ",g);
if(ISAP(S,T,T+))printf("Yes\n\n");
else printf("No\n\n");
}
return ;
}
HDU 3572(Task Schedule) ISAP做法的更多相关文章
- hdu 3572 Task Schedule (dinic算法)
pid=3572">Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 3572 Task Schedule (最大流)
C - Task Schedule Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 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
Task Schedule 题意:有N个任务,M台机器.每一个任务给S,P,E分别表示该任务的(最早开始)开始时间,持续时间和(最晚)结束时间:问每一个任务是否能在预定的时间区间内完成: 注:每一个任 ...
- 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(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(当前弧优化Dinic算法)
Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...
- hdu 3572 Task Schedule (Dinic模板)
Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...
- 图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)
Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...
随机推荐
- Python 代码块左移或右移
(就 IDE 是 PyCharm 来说) 选中代码块: 1)右移:直接 Tab 2)左移:Shift + Tab Python 对代码对齐要求很严格的. Python的对齐方式很重要,对齐方式决定了 ...
- html调用摄像头的方法汇总
1.在PC端打开摄像头的方法:(移动端不能使用) 能够实现打开摄像头并截图 <!doctype html> <html lang="en"> <hea ...
- Android工程:引用另一个Android工程的方法详解
本篇文章是对在Android中引用另一个Android工程的方法进行了详细的分析介绍.需要的朋友参考下 现在已经有了一个Android工程A.我们想扩展A的功能,但是不想在A的基础上做开发,于是新 ...
- hdu_2817_高速幂
水~ #include <cstdio> #include <iostream> #include <cstring> #include <algorithm ...
- 点滴积累【C#】---C#实现上传照片到物理路径,并且将地址保存到数据库,
效果: 思路: 首先,获取图片物理地址,然后进行判断将图片保存到文件夹下,再将图片的信息保存到数据库. 数据库: create table image1 ( ID ,) primary key, Im ...
- C# ZPL II 命令打印标签
public class BarPrinter { public static byte[] ZPLPrinter(string p_title = "", string p_sp ...
- C# 版 防止 DNS 污染,获取域名真实 IP 地址
using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Net. ...
- numpy.ravel()/numpy.flatten()/numpy.squeeze()
numpy.ravel(a, order='C') Return a flattened array numpy.chararray.flatten(order='C') Return a copy ...
- python学习之count()
定义: count()方法用于统计对象中,某个字符出现的次数 语法: str.count(sub, start= ,end=len(string)) sub:搜索的对象 start和end:搜索的范围 ...
- Oracle VM VirtualBox虚拟机导出教程
Oracle VM VirtualBox虚拟机导出教程 | 浏览:583 | 更新:2015-01-31 11:21 1 2 3 4 5 6 7 分步阅读 有时我们需要把Oracle VM Virtu ...