hdu 2883(最大流)
来源:互联网 发布:大麦盒子怎么设置网络 编辑:程序博客网 时间:2024/06/02 18:49
kebab
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 195 Accepted Submission(s): 72
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.
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
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 101 10 6 32 10 4 22 101 10 5 32 10 4 2
Sample Output
YesNo
Source
2009 Multi-University Training Contest 9 - Host by HIT
Recommend
gaojie
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2883
ps:百度的排版真是挫阿。。。这题本来应该1A的,却因为Yes写成YES,wa了4次,囧
懒得写构图,转作者题解:
很巧的一道题目,附出题人的解题报告:
将所有的到达时间和结束时间按升序排序,得到 x <= 2n-1 个时间区间。建立网络流模型:s为源,t为汇,每个顾客i作为一个结点并连边(s, i, ni*ti),每个区间j作为一个结点并连边(j, t, (ej-sj)*M),其中sj, ej分别表示区间j的起始时间和终止时间。对任意顾客i和区间j,若 [sj, ej] 完全包含在 [si, ei] 之中,则连边(i, j, INF)。若最大流等于 ∑ni*ti 则是 Yes,否则是 No。
代码:
#include<cstdio>#include<algorithm>using namespace std;const int mm=222222;const int mn=2222;const int oo=1000000000;int node,src,dest,edge,tot;int ver[mm],flow[mm],next[mm];int head[mn],work[mn],dis[mn],q[mn],need[mn],s[mn],e[mn],a[mn];inline int min(int a,int b){ return a<b?a:b;}inline void prepare(int _node,int _src,int _dest){ node=_node,src=_src,dest=_dest; for(int i=0; i<node; ++i)head[i]=-1; edge=0;}inline void addedge(int u,int v,int c){ ver[edge]=v,flow[edge]=c,next[edge]=head[u],head[u]=edge++; ver[edge]=u,flow[edge]=0,next[edge]=head[v],head[v]=edge++;}bool Dinic_bfs(){ int i,u,v,l,r=0; for(i=0; i<node; ++i)dis[i]=-1; dis[q[r++]=src]=0; for(l=0; l<r; ++l) for(i=head[u=q[l]]; i>=0; i=next[i]) if(flow[i]&&dis[v=ver[i]]<0) { dis[q[r++]=v]=dis[u]+1; if(v==dest)return 1; } return 0;}int Dinic_dfs(int u,int exp){ if(u==dest)return exp; for(int &i=work[u],v,tmp; i>=0; i=next[i]) if(flow[i]&&dis[v=ver[i]]==dis[u]+1&&(tmp=Dinic_dfs(v,min(exp,flow[i])))>0) { flow[i]-=tmp; flow[i^1]+=tmp; return tmp; } return 0;}int Dinic_flow(){ int i,ret=0,delta; while(Dinic_bfs()) { for(i=0; i<node; ++i)work[i]=head[i]; while(delta=Dinic_dfs(src,oo))ret+=delta; } return ret;}int main(){ int i,c,t,n,m,sum; while(scanf("%d%d",&n,&m)!=-1) { for(i=1,tot=sum=0; i<=n; ++i) { scanf("%d%d%d%d",&s[i],&c,&e[i],&t); need[i]=c*t; sum+=need[i]; a[tot++]=s[i]; a[tot++]=e[i]; } sort(a,a+tot); for(i=1,c=0; i<tot; ++i) if(a[c]!=a[i])a[++c]=a[i]; prepare(n+c+2,0,n+c+1); for(i=1; i<=n; ++i)addedge(src,i,need[i]); for(i=1; i<=c; ++i) { addedge(i+n,dest,(a[i]-a[i-1])*m); for(t=1; t<=n; ++t) if(s[t]<=a[i-1]&&e[t]>=a[i])addedge(t,i+n,oo); } if(Dinic_flow()==sum)printf("Yes\n"); else printf("No\n"); } return 0;}
- hdu 2883(最大流)
- hdu 2883 最大流
- hdu 2883 (最大流)
- hdu 2883 kebab(最大流)
- Hdu 2883 最大流 区间 判满流
- hdu 2883(最大流、判满流)
- HDU 2883 kebab(离散化+最大流)
- hdu 2883 kebab 【网络最大流】
- HDU 2883 kebab(最大流)
- HDU - 2883 kebab (最大流)
- HDU 2883 kebab 最大流(纯靠建图)
- HDU 2883 kebab(最大流,满流)
- HDU 2883 kebab(离散化+最大流)
- HDU 2883 kebab(离散化+最大流)
- HDU 2883 kebab 最大流建模
- hdu 2883 kebab (最大流 + 建图)
- 【最大流】HDU 3572
- hdu 3572最大流
- Java Thread Join方法
- 单例模式的几种实现及其比较
- 线性表中插入元素
- Linux系统命令及其使用详解
- Ubuntu Linux 8.04系统下智能拼音输入法
- hdu 2883(最大流)
- ASP.NET中MD5和SHA1的几种方法
- Java5泛型的用法,T.class的获取和为擦拭法站台
- 从百度文库看企业内部信息泄漏
- poj1087
- poj 3656 Ants
- protocol buffer 的proto文件
- 如何使用java泛型
- 这已经是过去