kebab

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1603    Accepted Submission(s): 677

Problem Description
Almost
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.

 
Input
There
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

 
Output
If the roaster can satisfy all the customers, output “Yes” (without quotes). Otherwise, output “No”.
 
Sample Input
2 10
1 10 6 3
2 10 4 2

2 10
1 10 5 3
2 10 4 2

 
Sample Output
Yes
No
 
Source
 
题意:

有不多于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(构图+最大流+压缩区间)的更多相关文章

  1. hdu 3572(构图+最大流)

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

  2. HDU 2883 kebab(最大流)

    HDU 2883 kebab 题目链接 题意:有一个烧烤机,每次最多能烤 m 块肉.如今有 n 个人来买烤肉,每一个人到达时间为 si.离开时间为 ei,点的烤肉数量为 ci,每一个烤肉所需烘烤时间为 ...

  3. 基于Zlib算法的流压缩、字符串压缩源码

    原文:基于Zlib算法的流压缩.字符串压缩源码 Zlib.net官方源码demo中提供了压缩文件的源码算法.处于项目研发的需要,我需要对内存流进行压缩,由于zlib.net并无相关文字帮助只能自己看源 ...

  4. HDU 1557 权利指数 国家压缩 暴力

    HDU 1557 权利指数 状态压缩 暴力 ACM 题目地址:HDU 1557 权利指数 题意:  中文题,不解释. 分析:  枚举全部集合,计算集合中的和,推断集合里面的团体是否为关键团队. 代码: ...

  5. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. hdu 3308 最长连续上升区间

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. Mirror--日志流压缩

    在SQL SERVER 2008之后,主库和镜像库之间的日志流传送会默认使用压缩,压缩一方面降低了网络压力,另一方面增大了镜像两端的CPU压力. 可以打开 TF 1462 来关闭日志流压缩 SQL S ...

  8. hdu 2883 kebab(时间区间压缩 &amp;&amp; dinic)

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

  9. F - kebab HDU - 2883 (最大流构图)

    Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on a long thin stic ...

随机推荐

  1. Object.defineProperty基本用法

    1. 基本形式 Object.defineProperty(obj,prop,descriptor) 参数说明: obj: 必需,目标对象prop: 必需,需定义或修改属性的名字descriptor: ...

  2. linux 小技巧

      http://blog.csdn.net/xianjie0318/article/details/75712990 1.按内存从大到小排列进程:  ps -eo "%C : %p : % ...

  3. Codeforces Round #311 (Div. 2)B. Pasha and Tea二分

    B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. POJ1015 DP

    Jury Compromise Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28927   Accepted: 7676 ...

  5. Centos下iptables常用命令

    安装iptablesyum install iptables-services 重启防火墙使配置文件生效systemctl restart iptables.service 设置iptables防火墙 ...

  6. [技巧篇]17.那些年一直再逃避的问题,还债Web阶段!

    四海行唐的一阶段和二阶段的时候,再使用数据的时候总是使用List<Map<String,Object>>的东西,但是胖先生一直不怎么喜欢! 所以我再凌云17的Web阶段的时候, ...

  7. 【C++对象模型】第五章 构造、解构、拷贝 语意学

    1.构造语义学 C++的构造函数可能内带大量的隐藏码,因为编译器会扩充每一个构造函数,扩充程度视 class 的继承体系而定.一般而言编译器所做的扩充操作大约如下: 所有虚基类成员构造函数必须被调用, ...

  8. SpringBoot Caused by: java.lang.NoClassDefFoundError: org/apache/tomcat/util/descriptor/tld/TldParser

    最近尝试着用spring boot ,页面模版使用的jsp,在pom里配置了对jsp的支持: <dependency> <groupId>org.apache.tomcat.e ...

  9. 【SPOJ】2319 BIGSEQ - Sequence

    [算法]数位DP [题解]动态规划 题目要求的是大整数……没办法只写了小数字的,感觉应该没错. 大题框架是最大值最小化的二分问题. 对于每一块要求count(b)-count(a-1)≥s 已知a如何 ...

  10. {转}用ADMM求解大型机器学习问题

    [本文链接:http://www.cnblogs.com/breezedeus/p/3496819.html] 从等式约束的最小化问题说起:                               ...