HDU3572_Task Schedule(网络流最大流)
解题报告
题意:
工厂有m台机器,须要做n个任务。对于一个任务i。你须要花费一个机器Pi天,并且,開始做这个任务的时间要>=Si,完毕这个任务的时间<=Ei。
对于一个任务,仅仅能由一个机器来完毕。一个机器同一时间仅仅能做一个任务。
可是,一个任务能够分成几段不连续的时间来完毕。问,是否能做完所有任务。
思路:
网络流在于建模,这题建模方式是:
把每一天和每一个任务看做点。由源点到每一任务。建容量为pi的边(表示任务须要多少天完毕)。
每一个任务到每一天,若是能够在这天做任务,建一条容量为1的边。最后。把每天到汇点再建一条边容量m(表示每台机器最多工作m个任务)。
#include <map>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 99999999
using namespace std;
int n,m,l[2010],head[2010],cnt,M;
struct node
{
int v,w,next;
} edge[555000];
void add(int u,int v,int w)
{
edge[M].v=v;
edge[M].w=w;
edge[M].next=head[u];
head[u]=M++; edge[M].v=u;
edge[M].w=0;
edge[M].next=head[v];
head[v]=M++;
}
int bfs()
{
memset(l,-1,sizeof(l));
l[0]=0;
int i,u,v;
queue<int >Q;
Q.push(0);
while(!Q.empty())
{
u=Q.front();
Q.pop();
for(i=head[u]; i!=-1; i=edge[i].next)
{
v=edge[i].v;
if(l[v]==-1&&edge[i].w>0)
{
l[v]=l[u]+1;
Q.push(v);
}
}
}
if(l[cnt]>0)return 1;
return 0;
}
int dfs(int u,int f)
{
int a,i;
if(u==cnt)return f;
for(i=head[u]; i!=-1; i=edge[i].next)
{
int v=edge[i].v;
if(l[v]==l[u]+1&&edge[i].w>0&&(a=dfs(v,min(f,edge[i].w))))
{
edge[i].w-=a;
edge[i^1].w+=a;
return a;
}
}
l[u]=-1;//没加优化会T
return 0;
}
int main()
{
int t,i,j,s,p,e,k=1;
scanf("%d",&t);
while(t--)
{
M=0;
memset(head,-1,sizeof(head));
scanf("%d%d",&n,&m);
int sum=0,maxx=0;
for(i=1; i<=n; i++)
{
scanf("%d%d%d",&p,&s,&e);
add(0,i,p);
sum+=p;
if(maxx<e)
maxx=e;
for(j=s; j<=e; j++)
add(i,j+n,1);
}
cnt=n+maxx+1;
for(i=1; i<=maxx; i++)
{
add(n+i,cnt,m);
}
int ans=0,a;
while(bfs())
while(a=dfs(0,inf))
ans+=a;
printf("Case %d: ",k++);
if(ans==sum)
printf("Yes\n");
else printf("No\n");
printf("\n");
}
return 0;
}
Task Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3311 Accepted Submission(s): 1154
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.
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.
2
4 3
1 3 5
1 1 4
2 3 7
3 5 9 2 2
2 1 3
1 2 2
Case 1: Yes Case 2: Yes
HDU3572_Task Schedule(网络流最大流)的更多相关文章
- POJ 1459-Power Network(网络流-最大流-ISAP)C++
Power Network 时间限制: 1 Sec 内存限制: 128 MB 题目描述 A power network consists of nodes (power stations, cons ...
- [POJ1273][USACO4.2]Drainage Ditches (网络流最大流)
题意 网络流最大流模板 思路 EK也不会超时 所以说是一个数据比较水的模板题 但是POJ有点坑,多组数据,而且题目没给 哭得我AC率直掉 代码 用的朴素Dinic #include<cstdio ...
- HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)
HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question ...
- HDU1532 网络流最大流【EK算法】(模板题)
<题目链接> 题目大意: 一个农夫他家的农田每次下雨都会被淹,所以这个农夫就修建了排水系统,还聪明的给每个排水管道设置了最大流量:首先输入两个数n,m ;n为排水管道的数量,m为节点的数量 ...
- Redraw Beautiful Drawings(hdu4888)网络流+最大流
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- A simple Gaussian elimination problem.(hdu4975)网络流+最大流
A simple Gaussian elimination problem. Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65 ...
- 【bzoj3130】[Sdoi2013]费用流 二分+网络流最大流
题目描述 Alice和Bob做游戏,给出一张有向图表示运输网络,Alice先给Bob一种最大流方案,然后Bob在所有边上分配总和等于P的非负费用.Alice希望总费用尽量小,而Bob希望总费用尽量大. ...
- 【bzoj1822】[JSOI2010]Frozen Nova 冷冻波 计算几何+二分+网络流最大流
题目描述 WJJ喜欢“魔兽争霸”这个游戏.在游戏中,巫妖是一种强大的英雄,它的技能Frozen Nova每次可以杀死一个小精灵.我们认为,巫妖和小精灵都可以看成是平面上的点. 当巫妖和小精灵之间的直线 ...
- 【bzoj1733】[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 二分+网络流最大流
题目描述 Farmer John is constructing a new milking machine and wishes to keep it secret as long as possi ...
随机推荐
- JAVA中IO和异常处理练习
1.SystemI\O练习:1)通过键盘输入若干字符,并通过显示器输出:2)定义一个静态方法validOrNot()用于对输入的字符进行合法性校验,若包含非英文字符,则抛出IllegalStringE ...
- Part Acquisition(spfa输出路径)
Part Acquisition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4080 Accepted: 1742 ...
- jsp验证表单后再提交
在提交表单时,我们常常需要验证核实表单内容,若都不为空时,方能提交:若有文本框为空则不提交,并获取鼠标焦点到文本框上 ,所以我们可以利用onsubmit的方法来做,请看下面例子: <html&g ...
- Python模拟登陆
模拟人人登陆 #encoding=utf-8 import urllib2 import urllib import cookielib def renrenBrower(url,user,passw ...
- English learning method ---学英语重中之重打通“任督二脉”
漫漫十年艰辛路,英语学习之旅 曾经秉承“路漫漫其修远兮,吾将上下而求索”的信念,初一那年了解到原来(a b c d e f g) 不仅仅读作(啊,波,词,的,额,佛,哥),在英语的世界中它有另外的读法 ...
- Android:源码环境编译自定义的APP到ROM(System Image)中
有时候我们需要在源码环境中增加自己的应用或模块,随ROM一起发布. 下面讲述相关步骤: 1. 首先可以在SDK环境下进行编码设计(如果你的APP不涉及到emulator无法模拟的硬件的话) 也可以参考 ...
- mvc请求过程总结
前言 最近在思考一个问题,我的学习方法一般主要是看博客来学习新东西,但是光看,基本也没总结过,所以经常会出现这样的问题,某个知识点我知道,但是就是不能很好的表达出来,很简单的东西往往都不知道如何简短精 ...
- 【Eclipse】修改java代码不强制重启
找到tomcat的server.xml文件,修改以下代码,重新发布重启.然后修改java代码就可以不用重启了. 将reloadable=“true”改成reloadable="false&q ...
- 【Oracle】wmsys.wm_concat函数字段值为空
这个是因为字符集的问题,和空值是没关系的.其实已经取到了数据,可以验证一下返回的不是0,但是由于这个里面有个chr(0)字符,而且可能第一个字符就是chr(0),所以就显示得怪异的空现象.至于为何会出 ...
- CURL基础
下载单个文件: #下载单个文件,默认将输出打印到标准输出中(STDOUT)中curl http://www.centos.org # 将文件下载到本地并命名为mygettext.html curl - ...