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 ...
随机推荐
- LibreOJ #6190. 序列查询(线段树+剪枝)
莫队貌似是过不了的,这题是我没见过的科技... 首先区间按右端点排序,然后一个扫描线,扫到某个区间右端点时候计算答案,线段树上节点的信息并不需要明确定义,我们只要求线段树做到当前扫到now时,查询[L ...
- [AHOI2008] 逆序对
link 我们可以很容易的推断出$-1$是单调不降的,若$i>j$且$a_i$与$a_j$都没有填数,若填完之后$a_i>a_j$或者$a_i<a_j$,则对答案产生影响的只在$[i ...
- 打开cmd窗口新技巧get
1.在当前目录下,按住shift键+点击右键,选择在此处打开命令窗口 很多时候我们需要打开命令行然后进入到相应目录进行一些操作. 常规的做法是: Win+R打开运行窗口 输入"cmd&quo ...
- lnmp git ruby sass 安装
1 cd .. 2 ls 3 cd mzx/ 4 ls 5 cd 桌面 6 cd lnmp1.4-full/ //到lnmp 的官网上下载后,根据官网的提示来安装lump 7 ls 8 install ...
- Python to list users in AWS
code import boto3 c1=boto3.client('iam') #list_users will be a dict users=c1.list_users() #transfer ...
- 数学:拓展BSGS
当C不是素数的时候,之前介绍的BSGS就行不通了,需要用到拓展BSGS算法 方法转自https://blog.csdn.net/zzkksunboy/article/details/73162229 ...
- sqlserver xml转表 及(cross apply与outer apply)
一. 需求是需要把','分割的字符串转为表,便于做关联查询,于是发现可以通过xml转为表,如下: declare @XXX xml set @XXX = ' <v> <aa>1 ...
- Python编写在Maya中查看文件列表的插件
之前写过一篇用Python遍历文件夹的文章,今天把代码扩展一下,做成一个有UI用户界面的Maya插件,可以直接在Maya中运行: 功能是显示磁盘分区目录下的文件列表,通过定制也可以查看任意目录下的文件 ...
- bzoj 4378: [POI2015]Logistyka ——树桩数组+离散化
Description 维护一个长度为n的序列,一开始都是0,支持以下两种操作:1.U k a 将序列中第k个数修改为a.2.Z c s 在这个序列上,每次选出c个正数,并将它们都减去1,询问能否进行 ...
- bzoj 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列——map+hash+转换
Description N(1<=N<=100000)头牛,一共K(1<=K<=30)种特色, 每头牛有多种特色,用二进制01表示它的特色ID.比如特色ID为13(1101), ...