HDU 2883 kebab
2015-06-05 12:52
429 查看
kebab
Time Limit: 1000msMemory Limit: 32768KB
This problem will be judged on HDU. Original ID: 2883
64-bit integer IO format: %I64d Java class name: Main
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
2009 Multi-University Training Contest 9 - Host by HIT解题:最大流判满流
#include <bits/stdc++.h> using namespace std; const int maxn = 2000; const int INF = 0x3f3f3f3f; struct arc{ int to,flow,next; arc(int x = 0,int y = 0,int z = -1){ to = x; flow = y; next = z; } }e[1000000]; struct Server{ int s,n,e,t; }SV[500]; int d[maxn],head[maxn],p[maxn],cur[maxn],tot,S,T,n,m; void add(int u,int v,int flow){ e[tot] = arc(v,flow,head[u]); head[u] = tot++; e[tot] = arc(u,0,head[v]); head[v] = tot++; } bool bfs(){ queue<int>q; memset(d,-1,sizeof d); d[S] = 1; q.push(S); while(!q.empty()){ int u = q.front(); q.pop(); for(int i = head[u]; ~i; i = e[i].next){ if(e[i].flow && d[e[i].to] == -1){ d[e[i].to] = d[u] + 1; q.push(e[i].to); } } } return d[T] > -1; } int dfs(int u,int low){ if(u == T) return low; int tmp = 0,a; for(int &i = cur[u]; ~i; i = e[i].next){ if(e[i].flow && d[e[i].to] == d[u]+1 &&(a=dfs(e[i].to,min(low,e[i].flow)))){ tmp += a; low -= a; e[i].flow -= a; e[i^1].flow += a; if(!low) break; } } if(!tmp) d[u] = -1; return tmp; } int dinic(){ int ret = 0; while(bfs()){ memcpy(cur,head,sizeof head); ret += dfs(S,INF); } return ret; } int main(){ while(~scanf("%d%d",&n,&m)){ memset(head,-1,sizeof head); int cnt = 0; for(int i = 1; i <= n; ++i){ scanf("%d%d%d%d",&SV[i].s,&SV[i].n,&SV[i].e,&SV[i].t); p[cnt++] = SV[i].s; p[cnt++] = SV[i].e; } sort(p,p+cnt); cnt = unique(p,p+cnt)-p; int sum = S = tot = 0; T = cnt+n+1; for(int i = 1; i < cnt; ++i) add(i+n,T,m*(p[i] - p[i-1])); for(int i = 1; i <= n; ++i){ add(S,i,SV[i].n*SV[i].t); sum += SV[i].n*SV[i].t; for(int j = 1; j < cnt; ++j) if(SV[i].s <= p[j-1] && SV[i].e >= p[j]) add(i,j+n,INF); } puts(dinic() == sum?"Yes":"No"); } return 0; }
View Code
相关文章推荐
- 各种加解密算法比較
- 0-1背包问题
- UITableView_5-团购简单实现,nib封装实现,模型封装实现
- 屏幕手势向导页面
- GStreamer 1.2 on the Raspberry Pi
- 利用波特五力模型理解钢铁行业不断变化的吸引力
- 对其他团队的评论
- cdoj1092-韩爷的梦 (字符串hash)【hash】
- JMS消息服务
- 猜拳 三局两胜
- cmd连接mysql的方法详解
- 设计模式C++实现(8)——代理模式
- SUSE环境编译cannot find -lcrypto
- CentOS/Linux安装VNCserver
- java万年历
- TCP/IP协议簇
- 关于表格CELL重用dequeueReusableCellWithIdentifier
- Problem B: [NOIP2013]花匠 D2 T2
- jQuery UI炫酷雨滴落在水面上的波纹涟漪特效
- iOS面试题