Task Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7015    Accepted Submission(s): 2192

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

 
题意:n个任务m台机器,其中完成第i个任务需要p[i]天,需要在第s[i]天或者其之后开始,需要在第e[i]天或者其之前完成,任务可以随时开始或者停止,问在给定的条件下能否完成所有的任务。
题解:构造超级源点以及超级汇点,超级源点向每个i点连一条容量为p[i]的边,每一个i点向其起始天和完成天区间内的每一天连一条容量为1的边,然后所有的天都向所有的机器连一条容量为1的边,最后所有的机器向汇点连一条无穷大的边,做一次最大流,如果max_flow == sum(p[i]),则证明能够完成所有的任务,别把下标弄混了。。弄错了一个下标,WA了两次。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int N = ;
const int INF = ;
struct Edge{
int v,w,next;
}edge[N*N];
int head[N];
int p[N],s[N],e[N];
int level[N];
int tot,n,m;
void init()
{
memset(head,-,sizeof(head));
tot=;
}
void addEdge(int u,int v,int w,int &k)
{
edge[k].v = v,edge[k].w=w,edge[k].next=head[u],head[u]=k++;
edge[k].v = u,edge[k].w=,edge[k].next=head[v],head[v]=k++;
}
int BFS(int src,int des)
{
queue<int>q;
memset(level,,sizeof(level));
level[src]=;
q.push(src);
while(!q.empty())
{
int u = q.front();
q.pop();
if(u==des) return ;
for(int k = head[u]; k!=-; k=edge[k].next)
{
int v = edge[k].v;
int w = edge[k].w;
if(level[v]==&&w!=)
{
level[v]=level[u]+;
q.push(v);
}
}
}
return -;
}
int dfs(int u,int des,int increaseRoad){
if(u==des||increaseRoad==) return increaseRoad;
int ret=;
for(int k=head[u];k!=-;k=edge[k].next){
int v = edge[k].v,w=edge[k].w;
if(level[v]==level[u]+&&w!=){
int MIN = min(increaseRoad-ret,w);
w = dfs(v,des,MIN);
if(w > )
{
edge[k].w -=w;
edge[k^].w+=w;
ret+=w;
if(ret==increaseRoad) return ret;
}
else level[v] = -;
if(increaseRoad==) break;
}
}
if(ret==) level[u]=-;
return ret;
}
int Dinic(int src,int des)
{
int ans = ;
while(BFS(src,des)!=-) ans+=dfs(src,des,INF);
return ans;
}
int main()
{
int tcase;
scanf("%d",&tcase);
int t = ;
while(tcase--){
init();
scanf("%d%d",&n,&m);
int MIN = INF,MAX = -,sum = ;
for(int i=;i<=n;i++){
scanf("%d%d%d",&p[i],&s[i],&e[i]);
MIN = min(s[i],MIN);
MAX = max(e[i],MAX);
sum+=p[i];
}
int start = ,ed = n+(MAX-MIN+)+m+;
for(int i=;i<=n;i++){
addEdge(start,i,p[i],tot);
}
for(int i=;i<=n;i++){
for(int j=s[i]+n;j<=e[i]+n;j++){
addEdge(i,j,,tot);
}
}
for(int i=MIN+n;i<=MAX+n;i++){
for(int j=n+MAX-MIN++;j<ed;j++){
addEdge(i,j,,tot);
}
}
for(int i=n+MAX-MIN++;i<ed;i++){
addEdge(i,ed,INF,tot);
}
int max_flow = Dinic(start,ed);
printf("Case %d: ",t++);
if(max_flow==sum){
printf("Yes\n");
}else{
printf("No\n");
}
printf("\n");
}
return ;
}

hdu 3572(构图+最大流)的更多相关文章

  1. hdu 2883(构图+最大流+压缩区间)

    kebab Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  2. HDU 3572 Task Schedule(拆点+最大流dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  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(最大流)2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC

    题意: 告诉我们有m个任务和k个机器.第i个任务需要ci天完成,最早从第ai天开始,最晚在第bi天结束.每台机器每天可以执行一个任务.问,是否可以将所有的任务都按时完成? 输入: 首行输入一个整数t, ...

  5. HDU 3572 最大流

    [题意]有n个任务,每个任务必须开始于第Si天之后(包括Si),结束于第Ei天之前(包括Ei),每个任务持续的时间为Pi,现在有m台机器,每台每天只能专注做其中一件任务,每个任务做的时间可以不连续.问 ...

  6. HDU 3572 Task Schedule(最大流判断满流)

    https://vjudge.net/problem/HDU-3572 题意: 有N个作业和M台机器,每个作业都有一个持续时间P,工作的日期为S~E.作业可以断断续续的在不同机器上做,每台机器每次只可 ...

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

  8. hdu 3572 最大流判断满流

    #include<stdio.h> #include<string.h> #include<queue> using namespace std; #define ...

  9. hdu 3572 Task Schedule【 最大流 】

    求出最大流,再判断是否满流 先不理解为什么要这样建图 后来看了这一篇题解 http://blog.csdn.net/u012350533/article/details/12361003 把0看做源点 ...

随机推荐

  1. X day3

    题目 官方题解 T1: 一道水题 #include<iostream> #include<cstring> #include<cstdio> #include< ...

  2. pandas模块(数据分析)------Series

    pandas是一个强大的Python数据分析的工具包. pandas是基于NumPy构建的. pandas的主要功能: 具备对其功能的数据结构DataFrame.Series 集成时间序列功能 提供丰 ...

  3. Django ORM 查询

    过滤器 过滤器 作用 all() 查出所有行 filter() 可以添加过滤条件 order_by() 查出所有数据,如果有参数则按参数排序,参数是字符串 ,如:"-username&quo ...

  4. python 栈和队列

    class Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push ...

  5. sql service 事务与锁

    了解事务和锁 事务:保持逻辑数据一致性与可恢复性,必不可少的利器. 锁:多用户访问同一数据库资源时,对访问的先后次序权限管理的一种机制,没有他事务或许将会一塌糊涂,不能保证数据的安全正确读写. 死锁: ...

  6. C#泛型实例详解

    本文以实例形式讲述了C#泛型的用法,有助于读者深入理解C#泛型的原理,具体分析如下: 首先需要明白什么时候使用泛型: 当针对不同的数据类型,采用相似的逻辑算法,为了避免重复,可以考虑使用泛型. 一.针 ...

  7. jquery动画切换引擎插件 Velocity.js 学习01

    一.Velocity.js介绍 Velocity是一个jQuery插件,重新实现了$.animate() 来产生更高的性能(速度也比CSS动画库更快),而包括新的功能,以提高动画工作流程. Veloc ...

  8. 51Nod 1095 Anigram单词 | Hash

    Input示例 5 add dad bad cad did 3 add cac dda Output示例 1 0 2 题意:一系列字符串,查询字符串S,能通过其他字符串交换串内字符顺序得到的字符串个数 ...

  9. mysql 在查询结果中进行二次查询

    第一次查询:查询身份证编号和出现次数 select cardid,count(cardid) as total from p_person_info group by cardid 在第一次查询结果进 ...

  10. Django ORM常用的函数以及修饰词

    函数名称或修饰词 说明 filter() 返回符合指定条件的QuerySet exclude() 返回不符合指定条件的QuerySet ordey_by() 串接到QuerySet之后,针对某一指定的 ...