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

 
解题:最大流判满流
 
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int INF = 0x3f3f3f3f;
struct arc{
int to,flow,next;
arc(int x = ,int y = ,int z = -){
to = x;
flow = y;
next = z;
}
}e[];
struct Server{
int s,n,e,t;
}SV[];
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,,head[v]);
head[v] = tot++;
}
bool bfs(){
queue<int>q;
memset(d,-,sizeof d);
d[S] = ;
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] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[T] > -;
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == d[u]+ &&(a=dfs(e[i].to,min(low,e[i].flow)))){
tmp += a;
low -= a;
e[i].flow -= a;
e[i^].flow += a;
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic(){
int ret = ;
while(bfs()){
memcpy(cur,head,sizeof head);
ret += dfs(S,INF);
}
return ret;
}
int main(){
while(~scanf("%d%d",&n,&m)){
memset(head,-,sizeof head);
int cnt = ;
for(int i = ; 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 = ;
T = cnt+n+;
for(int i = ; i < cnt; ++i) add(i+n,T,m*(p[i] - p[i-]));
for(int i = ; i <= n; ++i){
add(S,i,SV[i].n*SV[i].t);
sum += SV[i].n*SV[i].t;
for(int j = ; j < cnt; ++j)
if(SV[i].s <= p[j-] && SV[i].e >= p[j]) add(i,j+n,INF);
}
puts(dinic() == sum?"Yes":"No");
}
return ;
}

HDU 2883 kebab的更多相关文章

  1. HDU 2883 kebab(最大流)

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

  2. hdu 2883 kebab 网络流

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

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

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

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

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

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

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

  6. kebab HDU - 2883(按时间段建点)

    题意: 有n个人去撸串,每个人都能决定自己的串上有几块肉,每一块肉都要花费一个单位时间才熟,烤炉一次能烤m块肉 给出每个人的起始时间.终止时间.要几串.每个串上有几块肉,问能否满足所有的人 (啥?题不 ...

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

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

  8. 网络流HDU 2883

    建图           源点  ->     每个人  ->           每段时间      ->      汇点 时间要离散化一下 分成一些时间段 权           ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

随机推荐

  1. python之路-------字符串与正則表達式

    1.1.#####去掉字符串中的转义符string.strip() print "hello\tworld\n" >>> word="\thello w ...

  2. CSS透明度设置支持IE,Chrome,Firefox浏览器

    CSS文件里设置例如以下就可以 filter:alpha(opacity=60); //支持IE opacity:0.6; //支持Chrome.Firefox

  3. Android Application 类共享全局数据

    android系统会为每一个程序执行时创建一个Application类的对象且仅创建一个.所以Application能够说是单例模式的一个类.且application对象的生命周期是整个程序中最长的, ...

  4. 2.IntelliJ IDEA 2017创建JavaEE项目

    转自:https://blog.csdn.net/qq_31628285/article/details/75139909?utm_source=blogxgwz0 IntelliJ IDEA 201 ...

  5. Mvc 返回文件直接下载

    今天碰到一个问题,前端点击下载文件,后端判断文件是否存在,不存在则自动生成文件(图片),返回前端会自动下载文件 网上查了一些  Mvc  action中返回File类型 设置一些contentType ...

  6. 8.queue

    #include <iostream> #include <stack> #include <algorithm> #include <list> #i ...

  7. windows下远程链接虚拟机Linux下MySQL数据库问题处理

    参考解决:https://www.cnblogs.com/blogforly/p/5997553.html 今天远程连接虚拟机中的MySQL数据库,一直连不上,在网上搜索了一下,发现原因是MySQL对 ...

  8. PostgreSQL Replication之第八章 与pgbouncer一起工作(3)

    8.3 配置您的第一个pgbouncer设置 一旦我们已经完成了pbouncer的编译与安装,我们可以容易地启动它.要做到这一点,我们已经在一个本地实例(p0和p1) 建立了两个数据库.在本例中,执行 ...

  9. HDU 3342 Legal or Not(判断环)

    Problem Description ACM-DIY is a large QQ group where many excellent acmers get together. It is so h ...

  10. linux指令快速复制粘贴[龟速更新中]

    由于有经常碰到要输入linux指令,但是却忘记了的情况.在家里我把常用的命令放到Xshell的快速命令集,但是在很多情况下不在家,可能用的他人电脑,以及在非Win环境下使用ssh时没有xshell使用 ...