HDU 2883 kebab

kebab

Time Limit: 1000ms

Memory 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

解题:最大流判满流

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 2000;
 4 const int INF = 0x3f3f3f3f;
 5 struct arc{
 6     int to,flow,next;
 7     arc(int x = 0,int y = 0,int z = -1){
 8         to = x;
 9         flow = y;
10         next = z;
11     }
12 }e[1000000];
13 struct Server{
14     int s,n,e,t;
15 }SV[500];
16 int d[maxn],head[maxn],p[maxn],cur[maxn],tot,S,T,n,m;
17 void add(int u,int v,int flow){
18     e[tot] = arc(v,flow,head[u]);
19     head[u] = tot++;
20     e[tot] = arc(u,0,head[v]);
21     head[v] = tot++;
22 }
23 bool bfs(){
24     queue<int>q;
25     memset(d,-1,sizeof d);
26     d[S] = 1;
27     q.push(S);
28     while(!q.empty()){
29         int u = q.front();
30         q.pop();
31         for(int i = head[u]; ~i; i = e[i].next){
32             if(e[i].flow && d[e[i].to] == -1){
33                 d[e[i].to] = d[u] + 1;
34                 q.push(e[i].to);
35             }
36         }
37     }
38     return d[T] > -1;
39 }
40 int dfs(int u,int low){
41     if(u == T) return low;
42     int tmp = 0,a;
43     for(int &i = cur[u]; ~i; i = e[i].next){
44         if(e[i].flow && d[e[i].to] == d[u]+1 &&(a=dfs(e[i].to,min(low,e[i].flow)))){
45             tmp += a;
46             low -= a;
47             e[i].flow -= a;
48             e[i^1].flow += a;
49             if(!low) break;
50         }
51     }
52     if(!tmp) d[u] = -1;
53     return tmp;
54 }
55 int dinic(){
56     int ret = 0;
57     while(bfs()){
58         memcpy(cur,head,sizeof head);
59         ret += dfs(S,INF);
60     }
61     return ret;
62 }
63 int main(){
64     while(~scanf("%d%d",&n,&m)){
65         memset(head,-1,sizeof head);
66         int cnt = 0;
67         for(int i = 1; i <= n; ++i){
68             scanf("%d%d%d%d",&SV[i].s,&SV[i].n,&SV[i].e,&SV[i].t);
69             p[cnt++] = SV[i].s;
70             p[cnt++] = SV[i].e;
71         }
72         sort(p,p+cnt);
73         cnt = unique(p,p+cnt)-p;
74         int sum = S = tot = 0;
75         T = cnt+n+1;
76         for(int i = 1; i < cnt; ++i) add(i+n,T,m*(p[i] - p[i-1]));
77         for(int i = 1; i <= n; ++i){
78             add(S,i,SV[i].n*SV[i].t);
79             sum += SV[i].n*SV[i].t;
80             for(int j = 1; j < cnt; ++j)
81                 if(SV[i].s <= p[j-1] && SV[i].e >= p[j]) add(i,j+n,INF);
82         }
83         puts(dinic() == sum?"Yes":"No");
84     }
85     return 0;
86 }

时间: 2024-08-26 18:18:18

HDU 2883 kebab的相关文章

HDU 2883 kebab(最大流)

HDU 2883 kebab 题目链接 题意:有一个烧烤机,每次最多能烤 m 块肉,现在有 n 个人来买烤肉,每个人到达时间为 si,离开时间为 ei,点的烤肉数量为 ci,每个烤肉所需烘烤时间为 di,注意一个烤肉可以切成几份来烤 思路:把区间每个点存起来排序后,得到最多2 * n - 1个区间,这些就表示几个互相不干扰的时间,每个时间内只可能有一个任务器做,这样建模就简单了,源点连向汇点,容量为任务需要总时间,区间连向汇点,容量为区间长度,然后每个任务如果包含了某个区间,之间就连边容量无限大

hdu 2883 kebab 网络流

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2883 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 delicio

HDU 2883 —— kebab

原题:http://acm.hdu.edu.cn/showproblem.php?pid=2883 #include<cstdio> #include<cstring> #include<string> #include<queue> #include<vector> #include<algorithm> #define inf 1e9 using namespace std; const int maxn = 41000; con

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

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

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

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

HDU - 2883 kebab (最大流)

题目大意:有一个烤肉老板,每个单位时间可以完成M的烤肉 现在有N位客人,给出每位客人来的时间,走的时间,烤肉的数量和每串烤肉所需的单位时间 问这个老板能否完成每位客人的需求 解题思路:这题和HDU 3572相似,但又不能像那题那样做,因为这题时间长度有点大 所以将时间区间当成一个点,将该区间连向超级汇点,容量为区间长度*M 将所有客人连向超级源点,容量为烤肉数量*每串烤肉所需时间 接下来的难点就是怎么将客人和时间区间连起来了 如果时间区间在客人来的时间和走的时间这段区间内,就表明这段时间可以用来

hdoj 2883 kebab 【经典最大流】

题目:hdoj 2883 kebab 题意:现在有n个人要烤肉,有m个烤肉架,然后给出每个人的烤肉开始时间si,结束时间ei,以及要烤肉的串数num,还有拷一串的时间ti,然后问你能不能满足所有人的要求. 分析:这是一个比较经典的最大流,经典在于建图方法,这个题目难点在于时间跨度在0---100 0000,如果时间短的话就可以用题目3572的做法了.点击打开链接 后面看了别人的建图方法,确实比较经典,经典在于把区间缩点了,这个题目的难点在于时间跨度大,那么我们可以把所有的时间点记录下来,然后排序

kebab (hdu 2883 网络流判满流 关键是缩点)

kebab Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1071    Accepted Submission(s): 447 Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on

hdoj 2883 kebab 【时间区间离散化 + 最大流】

kebab Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1273    Accepted Submission(s): 532 Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on