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. 【算法】【网络流24题】巨坑待填(成功TJ,有时间再填)

    ------------------------------------------------------------------------------------ 17/24 --------- ...

  2. 【单调队列】【P2627】 修剪草坪

    传送门 Wa这次竟然不是Uva的题 Description 在一年前赢得了小镇的最佳草坪比赛后,Farm John变得很懒,再也没有修剪过草坪.现在,新一轮的最佳草坪比赛又开始了,Farm John希 ...

  3. vector去除重复的元素

    vector<int> v; sort(v.begin(),v.end()); v.erase(unique(v.begin(), v.end()), v.end());

  4. java oracle clob string 大字符串存储【转】

    单位用到了oracle存储string类型到数据库里的clob,上网查看资料找到解决方案.如下: public class ClobTest { static String url = "j ...

  5. linux shell脚本攻略笔记

    前一阵子系统学习了下<linux shell脚本攻略>这本书.在此记录下自己的学习笔记 1. 输出颜色字符  echo -e "\e[1:41m" 1表示背景色   2 ...

  6. [异常处理]class kafka.common.UnknownTopicOrPartitionException (kafka.server.ReplicaFetcherThread)

    在kafka.out日志里出现大量 ERROR [ReplicaFetcherThread-0-1], Error for partition [FLAG_DATA_SYC,1] to broker ...

  7. book_notes

    http://139.196.8.158/ https://caomall.worktile.com/tasks/projects/58fd73047619c44427c0d719 http://lo ...

  8. jq 数组定义,拼接~~~push应用

    var radio_checked_array = []; $("input[type='radio']").each(function(){ if($(this).attr('c ...

  9. php 获取周几

    date("l"); //date就可以获取英文的星期比如Sunday date("w"); //这个可以获取数字星期比如123,注意0是星期日 获取中文星期几 ...

  10. linux用户管理和文件权限

    linux用户管理和文件权限 新建用户:useradd ftpuser      useradd -g gxx userxx修改密码:passwd ftpuser新增用户组:# groupadd gr ...