kebab

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1243    Accepted Submission(s): 516

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

field=problem&key=2009+Multi-University+Training+Contest+9+-+Host+by+HIT&source=1&searchmode=source">2009 Multi-University Training Contest 9 - Host by HIT

题意描写叙述:有n个人来烤肉店吃烤肉。每一个人在si 时刻来ei 时刻离开而且点了ni 份,

每份烤肉要烤到ti 个单位时间才算烤熟,烤肉店里能够同一时候烤m份。问是否有一种计划

使得n个人都能够拿到自己的ni 份。

參考大牛解题思路:这道题本身不是非常难,网络流的模型也非经常见,可是这道题中(si,ei)的时间

跨度非常大(1<=si<=ei<=1000000),所以不能把时间区间直接拆分开建立模型。这样顶点

个数太多,会超时。这里,介绍一下学到的新技巧,我们能够把时间区间压缩:

time[]里保存所有的si 和 ei ,这样time[i]-time[i-1]就表示一段时间区间了。

这题和HDU 3572相似,但又不能像那题那样做,由于这题时间长度有点大 

所以将时间区间当成一个点。将该区间连向超级汇点,容量为区间长度*M 

将全部客人连向超级源点。容量为烤肉数量*每串烤肉所需时间 

接下来的难点就是怎么将客人和时间区间连起来了 ,

假设时间区间在客人来的时间和走的时间这段区间内,

就表明这段时间能够用来帮客人烤肉,所以能够连接。容量为inf

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
#define M 3000
#define inf 0x3f3f3f3f
int head[M],dis[M],st,t,n,m,cnt;
struct node{
int v,next,w;
}mp[M*M];
void add(int u,int v,int w){
mp[cnt].v=v;
mp[cnt].w=w;
mp[cnt].next=head[u];
head[u]=cnt++;
mp[cnt].v=u;
mp[cnt].w=0;
mp[cnt].next=head[v];
head[v]=cnt++;
}
int bfs(){
memset(dis,-1,sizeof(dis));
queue <int> q;
dis[st]=0;
q.push(st);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u];i!=-1;i=mp[i].next){
int v=mp[i].v;
if( mp[i].w>0 && dis[v]==-1){
dis[v]=dis[u]+1;
if(v==t) return 1;
q.push(v);
}
}
}
return 0;
}
int dinic(int s,int low){//依照凝视地方写就会wa,曾经这么写就能过啊。这次快wa哭了,,= =+
if(s==t || low==0) return low;
int a,ans=low;//ans=0;
for(int i=head[s];i!=-1;i=mp[i].next){
int v=mp[i].v;
if(mp[i].w>0 && dis[v]==dis[s]+1 && (a=dinic(v,min(ans/*low*/,mp[i].w)))){
mp[i].w-=a;
mp[i^1].w+=a;
// ans+=a;
// if(ans==low) break;
ans-=a;
if(ans==0) return low;
}
}
//return ans;
return low-ans;
}
int main(){
int tot,count,sum;
int s[M],e[M],num[M],ti[M],time[M];
while(~scanf("%d%d",&n,&m)){
sum=cnt=0;tot=1; count=0;
memset(head,-1,sizeof(head));
memset(time,0,sizeof(time));
for(int i=1;i<=n;i++){
scanf("%d%d%d%d",&s[i],&num[i],&e[i],&ti[i]);
sum+=num[i]*ti[i];
time[tot++]=s[i];
time[tot++]=e[i];
}
sort(time+1,time+tot);
for(int i=1;i<tot;i++)//消除反复区域
if(time[count]!=time[i])
time[++count]=time[i];
st=n+count+1;//起点
t=st+1; //汇点
for(int i=1;i<=n;i++)//起点到每一个顾客。权值为烤肉数乘以时间
add(st,i,num[i]*ti[i]);
for(int i=1;i<=count;i++){
add(n+i,t,m*(time[i]-time[i-1]));//时间区间到汇点,权值为单位时间完毕烤肉m乘以区间长度
for(int j=1;j<=n;j++){
if(s[j]<=time[i-1]&&e[j]>=time[i])
add(j,n+i,inf);//假设顾客的区间段
}
}
int ans=0;
while(bfs())
ans+=dinic(st,inf);
if(sum==ans) printf("Yes\n");
else printf("No\n");
}
return 0;
}

hdu 2883 kebab(时间区间压缩 &amp;&amp; dinic)的更多相关文章

  1. hdu 2883 kebab 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2883 Almost everyone likes kebabs nowadays (Here a ke ...

  2. HDU 2883 kebab(最大流)

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

  3. hdu 2883(构图+最大流+压缩区间)

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

  4. HDU 2883 kebab

    kebab Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 2883 ...

  5. 图论--网络流--最大流 HDU 2883 kebab(离散化)

    Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled ...

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

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

  7. SQL Server 判定时间是否在某个时间区间内

    * FROM sys.objects WHERE name=N'uF_IsRange_Date' AND [type]='FN') DROP FUNCTION uF_IsRange_Date GO S ...

  8. hdu 2079 选课时间

    hdu 2079 选课时间 题意:选的学分总和为n,并且学分为a的课有b种,总共有K(1<=k<=8)种学分不同的课,并且要选的学分最多为40:问选课方案有多少种?(学分相同的课即认为相同 ...

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

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

随机推荐

  1. mybatis一对多关系的关联查询

    问题描述:实现两张表的关联查询 学生表: 班级表: 要实现学生管理信息中有所在班级的名称,即如下图所示 1.对应学生表的pojo类写全班级表中的字段(适用于要连接的表字段较少的情况) sql语句直接在 ...

  2. IN、EXISTS的相关子查询用INNER JOIN 代替--性能优化

    如果保证子查询没有重复 ,IN.EXISTS的相关子查询可以用INNER JOIN 代替.比如: IN.EXISTS的相关子查询用INNER JOIN 代替--sql2000性能优化

  3. 推荐系统:MovivLens20M数据集解析

    MovieLens 是历史最悠久的推荐系统.它由美国 Minnesota 大学计算机科学与工程学院的 GroupLens 项目组创办,是一个非商业性质的.以研究为目的的实验性站点.MovieLens ...

  4. 安卓桌布显示的dip和px

    安卓程序设计界面显示设置图像大小,在layout.xml里面有dip和px选项,dip为 什么 暂时还不知道,或许是设计桌布的设定像素比率,px为像素值: 比如我的手机是 Lenovo K920,屏幕 ...

  5. element-ui按需引入

    { "name": "vue-test2", "description": "A Vue.js project", &q ...

  6. Uoj #218. 【UNR #1】火车管理 可持久化线段树+思维

    Code: #include<bits/stdc++.h> #define maxn 500005 using namespace std; int n,Q,ty,lastans=0; i ...

  7. vfs:open.c 源码学习

    nameidata路径查找辅助结构 open.c @do_sys_open @get_unused_fd_flags @do_filp_open 1.开始填充nameidata 2.开始填充file ...

  8. html第四节课

    css CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页. /*注释区域*/    此为注释语法 一.样式表 (一)样式表的分类 1.内联样式表 和HTML联合 ...

  9. VUE常见问题解决

    1.vue模板加载顺序 computed:例如分页的配置: created:dom加载前一般用来生成dom mounted:dom加载后用来覆盖渲染或者基于dom的操作 2.关于this指向的问题 通 ...

  10. 微信小程序-蓝牙连接

    最近的项目需要使用小程序的蓝牙功能与硬件设备进行连接相互传送数据指令,联调过程中发现一些问题,于是想着记录下来,方便以后查看! 1.0一般使用蓝牙功能肯定是想连接某一个蓝牙设备,所以需要知道这个蓝牙设 ...