hdu 2883(构图+最大流+压缩区间)
kebab
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1603 Accepted Submission(s): 677
everyone likes kebabs nowadays (Here a kebab means pieces of meat
grilled on a long thin stick). Have you, however, considered about the
hardship of a kebab roaster while enjoying the delicious food? Well,
here's a chance for you to help the poor roaster make sure whether he
can deal with the following orders without dissatisfying the customers.
Now
N customers is coming. Customer i will arrive at time si (which means
the roaster cannot serve customer i until time si). He/She will order ni
kebabs, each one of which requires a total amount of ti unit time to
get it well-roasted, and want to get them before time ei(Just at exactly
time ei is also OK). The roaster has a big grill which can hold an
unlimited amount of kebabs (Unbelievable huh? Trust me, it’s real!). But
he has so little charcoal that at most M kebabs can be roasted at the
same time. He is skillful enough to take no time changing the kebabs
being roasted. Can you help him determine if he can meet all the
customers’ demand?
Oh, I forgot to say that the roaster needs not
to roast a single kebab in a successive period of time. That means he
can divide the whole ti unit time into k (1<=k<=ti) parts such
that any two adjacent parts don’t have to be successive in time. He can
also divide a single kebab into k (1<=k<=ti) parts and roast them
simultaneously. The time needed to roast one part of the kebab well is
linear to the amount of meat it contains. So if a kebab needs 10 unit
time to roast well, he can divide it into 10 parts and roast them
simultaneously just one unit time. Remember, however, a single unit time
is indivisible and the kebab can only be divided into such parts that
each needs an integral unit time to roast well.
are multiple test cases. The first line of each case contains two
positive integers N and M. N is the number of customers and M is the
maximum kebabs the grill can roast at the same time. Then follow N lines
each describing one customer, containing four integers: si (arrival
time), ni (demand for kebabs), ei (deadline) and ti (time needed for
roasting one kebab well).
There is a blank line after each input block.
Restriction:
1 <= N <= 200, 1 <= M <= 1,000
1 <= ni, ti <= 50
1 <= si < ei <= 1,000,000
1 10 6 3
2 10 4 2
2 10
1 10 5 3
2 10 4 2
No
有不多于200个任务,每个任务要在si到ei这个时间段内完成,每个任务的任务量是ti*ni,只有一台机器,且其单位时间内可完成的任务量为m。现在问能否使所有的任务全部在规定的时间段内完成。
题解:这个题和之前做的一道任务分配的题很相似,但是那道题是将区间拆成一个个点拿出来,这个题点数太多是不行的,所以我们将区间排序,去重之后再加边,先从超级源点向每个人连ni*ti的边,然后每个人能够等待的时间区间连一条容量为INF的边,最后所有的时间区间都向汇点连一条(time[i]-time[i-1])*m的边,做最大流,如果max_flow==sum(ni*ti),那么这个这么多任务就是可以完成的.
#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 level[N];
int tot;
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 n,m;
int s[N],num[N],e[N],t[N];
int time[N];
int main()
{
while(scanf("%d%d",&n,&m)!=EOF){
init();
int k = ;
int sum = ;
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&s[i],&num[i],&e[i],&t[i]);
sum += num[i]*t[i];
time[++k] = s[i];
time[++k] = e[i];
}
sort(time+,time+k+);
int cnt = ;
for(int i=;i<=k;i++){
if(time[i]==time[i-]) continue;
time[++cnt] = time[i];
}
int src = ,des = n+cnt+;
for(int i=;i<=n;i++){
addEdge(src,i,num[i]*t[i],tot);
}
for(int i=;i<=n;i++){
for(int j=;j<=cnt;j++){
if(s[i]<=time[j-]&&time[j]<=e[i]){
addEdge(i,n+j,INF,tot);
}
}
}
for(int i=;i<=cnt;i++){
addEdge(n+i,des,(time[i]-time[i-])*m,tot);
}
if(Dinic(src,des)==sum) printf("Yes\n");
else printf("No\n");
}
return ;
}
hdu 2883(构图+最大流+压缩区间)的更多相关文章
- hdu 3572(构图+最大流)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 2883 kebab(最大流)
HDU 2883 kebab 题目链接 题意:有一个烧烤机,每次最多能烤 m 块肉.如今有 n 个人来买烤肉,每一个人到达时间为 si.离开时间为 ei,点的烤肉数量为 ci,每一个烤肉所需烘烤时间为 ...
- 基于Zlib算法的流压缩、字符串压缩源码
原文:基于Zlib算法的流压缩.字符串压缩源码 Zlib.net官方源码demo中提供了压缩文件的源码算法.处于项目研发的需要,我需要对内存流进行压缩,由于zlib.net并无相关文字帮助只能自己看源 ...
- HDU 1557 权利指数 国家压缩 暴力
HDU 1557 权利指数 状态压缩 暴力 ACM 题目地址:HDU 1557 权利指数 题意: 中文题,不解释. 分析: 枚举全部集合,计算集合中的和,推断集合里面的团体是否为关键团队. 代码: ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 3308 最长连续上升区间
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Mirror--日志流压缩
在SQL SERVER 2008之后,主库和镜像库之间的日志流传送会默认使用压缩,压缩一方面降低了网络压力,另一方面增大了镜像两端的CPU压力. 可以打开 TF 1462 来关闭日志流压缩 SQL S ...
- hdu 2883 kebab(时间区间压缩 && dinic)
kebab Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- F - kebab HDU - 2883 (最大流构图)
Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on a long thin stic ...
随机推荐
- 【算法】【网络流24题】巨坑待填(成功TJ,有时间再填)
------------------------------------------------------------------------------------ 17/24 --------- ...
- phalcon安装
参考网站:https://docs.phalconphp.com/zh/latest/reference/tools.html (中文版)cento6.5环境安装:cd ~mkdir phalconc ...
- RobHess的SIFT源码分析:imgfeatures.h和imgfeatures.c文件
SIFT源码分析系列文章的索引在这里:RobHess的SIFT源码分析:综述 imgfeatures.h中有SIFT特征点结构struct feature的定义,除此之外还有一些特征点的导入导出以及特 ...
- CentOS 6.5 下安装配置 mysql
如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.eclipse的安装(这个在之前的一篇随笔中已经有详细讲解了Linux学习之CentOS(七)--Cen ...
- Just Random HDU - 4790 思维题(打表找规律)分段求解
Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In ...
- bfs和优先队列求数据三角形最大值
此题用深搜很快就解决,我用宽度搜索和优先队列仅仅是为了练习他们的用法:深搜法在注释内: 1 #include<iostream> #include<cstring> #incl ...
- BI在连锁零售业应用
BI案例:BI在连锁零售业应用(ZT) Posted on 2015-08-25 09:31 xuzhengzhu 阅读(42) 评论(0) 编辑 收藏 第一部分:连锁零售企业上BI的必要性. 目前国 ...
- ZooKeeper观察者(十三)
观察者:扩展ZooKeeper而不影响写性能 尽管ZK运行地很好通过客户端直接连接来投票集群的成员,这个结构使它很难扩展出很多客户端.问题是当我们加入更多的投票成员时,写性能就会下降.这是因为一个写操 ...
- ZooKeeper食谱(八)
使用ZooKeeper构造高级别应用的指南 在这个文章中,你将会发现使用ZooKeeper来实现高级别功能的指南.所有的它们在客户端上被实现而不需要ZooKeeper特别的支持.希望社区将注意到这些约 ...
- ZooKeeper概述(三)
ZooKeeper:分布式应用的分布协调服务 ZooKeeper是一个为分布式应用提供的分布的开源的协调服务.它暴露一组简单的原子操作,分布式系统可以在这之上为同步,配置管理,和组和命名实现更高级的服 ...