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. bzoj3680: 吊打XXX(模拟退火)

    题目要求 最小(dis表示绳结到点i的距离),就是个广义费马点的题,模拟退火裸题QAQ 模拟退火就是优化后的爬山算法,一开始先随机一个平均点,接下来如果随机到的点比当前点劣,温度比较高的话也有几率跳过 ...

  2. linux添加vim编辑器和一些用法

    vim.tar文件在自己的百度云盘里面,linux目录下 上传vim.tar文件,解压 vim编辑文件的一些快捷方式: n+t打开文件所在目录,显示在左侧 ctrl+w+l 切换到右边文件ctrl+w ...

  3. STL之一:字符串用法详解

    转载于:http://blog.csdn.net/longshengguoji/article/details/8539471 字符串是程序设计中最复杂的变成内容之一.STL string类提供了强大 ...

  4. mybatis的模糊查询写法

    mybatis做like模糊查询   1.  参数中直接加入%% param.setUsername("%CD%");      param.setPassword("% ...

  5. [ 转载]Tomcat7 catalina.out 日志分割

    http://m.blog.csdn.net/blog/mark_qi/8864644 最近由于工作需要,tomcat 的catalina.out文件的不断扩大,导致系统磁盘空间边变小,而且管理也难于 ...

  6. 51Nod 1094 和为k的连续区间 | 水

    Input示例 6 10 1 2 3 4 5 6 Output示例 1 4 #include "cstdio" #include "algorithm" #in ...

  7. 【设计模式】 模式PK:策略模式VS状态模式

    1.概述 行为类设计模式中,状态模式和策略模式是亲兄弟,两者非常相似,我们先看看两者的通用类图,把两者放在一起比较一下. 策略模式(左)和状态模式(右)的通用类图. 两个类图非常相似,都是通过Cont ...

  8. Ubuntu12.04 安装LAMP及phpmyadmin

    1.安装 Apache apt-get install apache2 2.安装 PHP5 apt-get install php5 libapache2-mod-php5 3.安装 MySQL ap ...

  9. 最简单的图文教程,几步完成Git的公私钥配置

    操作的前提是,你有git账号,并且在自己的电脑上已经装好了TorToiseGit工具.下面开始简单的教程: 第一步:Windows-->所有程序-->TortoiseGit-->Pu ...

  10. WCF 同一个解决方案中控制台应用添加服务引用报错

    错误提示: “Unable to check out the current file. The file may be read-only or locked, or you may need to ...