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.

InputThere 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 
OutputIf 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
题解:建立超级原点start(0),超级汇点endd,超级原点向n个客人连边,权值为总服务时间(n[i]*t[i]),n个客人向离散化后的服务区间(当作点)连边,
权值为离散后的区间长度乘以m,最后将离散化后的区间向超级汇点连边,权值也为离散化后的区间长度*m,最后Dinic模板判断是否满流即可. 自己需要注意的一点是:客人离开的那个时间点,是正好离开,所以当前时间点并不能再烤串,因为烤完了后就到下一分钟了,下一分钟客人就不在了,所以不可以.
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=;
int w[maxn];
struct edge
{
int v,cap,rev;
};
int level[maxn],iter[maxn];
vector<edge>G[maxn];
void add(int u,int v,int cap)
{
G[u].push_back((edge){v,cap,(int)G[v].size()});
G[v].push_back((edge){u,,(int)G[u].size()-});
}
void bfs(int s)
{
memset(level,-,sizeof(level));
queue<int>que;
level[s]=;
que.push(s);
while(!que.empty()){
int u=que.front();
que.pop();
for(int i=;i<G[u].size();i++){
edge &e=G[u][i];
int v=e.v;
if(e.cap>&&level[v]<){
level[v]=level[u]+;
que.push(v);
}
}
}
}
int dfs(int u,int t,int f)
{
if(u==t)return f;
for(int &i=iter[u];i<G[u].size();i++){
edge &e=G[u][i];
int v=e.v;
if(e.cap>&&level[v]>level[u]){
int d=dfs(v,t,min(f,e.cap));
if(d>){
e.cap-=d;
G[v][e.rev].cap+=d;
return d;
}
}
}
return ;
}
int Dinic(int s,int t)
{
int flow=;
for(;;){
bfs(s);
if(level[t]<)return flow;
memset(iter,,sizeof(iter));
int f;
while((f=dfs(s,t,INF))>){
flow+=f;
}
}
return flow;
}
int lsh[maxn],cnt;
int s[maxn],ni[maxn],e[maxn],ti[maxn];
int n,m;
int main()
{
while(cin>>n>>m){
for(int i=;i<=;i++)G[i].clear();
memset(lsh,,sizeof(lsh));
int full_flow=;
cnt=;
for(int i=;i<=n;i++){
cin>>s[i]>>ni[i]>>e[i]>>ti[i];
lsh[++cnt]=s[i];
lsh[++cnt]=e[i];
full_flow+=ni[i]*ti[i];
}
sort(lsh+,lsh++cnt);
int len=unique(lsh+,lsh++cnt)-(lsh+);
int start=,endd=;
for(int i=;i<=n;i++){
add(start,i,ni[i]*ti[i]);
}
for(int i=;i<=n;i++){
for(int j=;j<len;j++){
if(lsh[j]>=s[i]&&lsh[j+]<=e[i]){
add(i,n+j,(lsh[j+]-lsh[j])*m);
}
}
}
for(int i=;i<len;i++){
add(n+i,endd,(lsh[i+]-lsh[i])*m);
}
int flow=Dinic(start,endd);
if(flow==full_flow)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return ;
}

F - kebab HDU - 2883 (最大流构图)的更多相关文章

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

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

  2. HDU 2883 kebab(最大流)

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

  3. HDU 1532 最大流入门

    1.HDU 1532 最大流入门,n个n条边,求第1点到第m点的最大流.只用EK做了一下. #include<bits/stdc++.h> using namespace std; #pr ...

  4. 网络流 - 最大流构图入门 bzoj 1305

    一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会“单向喜欢”).每个男孩 ...

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

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

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

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

  7. HDU 2883 kebab

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

  8. hdu 2883 kebab 网络流

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

  9. hdu 2686&&hdu 3376(拆点+构图+最小费用最大流)

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

随机推荐

  1. JAVAEE 和项目开发(第三课:HTTP的请求头和请求方式)

    HTTP 协议之请求格式   请求格式的结构:请求行:请求方式.请求的地址和 HTTP 协议版本 请求头:消息报头,一般用来说明客户端要使用的一些附加信息 空行: 位于请求行和请求数据之间,空行是必须 ...

  2. 禁用 Bootstrap 模态框(Modal) 点击空白时自动关闭

    在做项目的时候,来了这么一个需求,要求打开模态框后,点击空白的地方不让他自动关闭,只能点击关闭按钮才能关闭. 有了需求,就开始查找资料寻求解决的方法. 我找到的解决方法如下: $('#registCo ...

  3. meta标签小结

    1.手机页面所需: <meta name="viewport" content="width=device-width,initial-scale=1.0,mini ...

  4. java获取配置文件信息

    两个类 package com.censoft.util; import java.util.Properties; import java.io.*; import java.util.ArrayL ...

  5. chown virtualbox

    virtualbox安装 root@cbill-VirtualBox:/# chown --help用法:chown [选项]... [所有者][:[组]] 文件... 或:chown [选项]... ...

  6. Windows安装使用SonarQube7.4 对java项目进行代码质量扫描

    我这里使用7.4因为使用JDK是1.8 其它版本看下依赖版本就好 1.下载7.4版本安装包 https://binaries.sonarsource.com/CommercialDistributio ...

  7. 4)栈和队列-->受限线性表

    栈和队列叫  受限线性表  只不过他们插入和删除的位置  相对于之前的线性表有了限制   所以叫受限线性表 1)栈-->就是先进后出 2)队列-->先进先出 3)循环链表框图: 4)队列

  8. Flux转Mono next()

    import java.util.LinkedHashMap; import java.util.Map; import java.util.NoSuchElementException; impor ...

  9. SQL基础教程(第2版)第2章 查询基础:练习题

    SELECT product_name, regist_date FROM Product WHERE regist_date > '2009-04-28'; ① ~ ③中的 SQL 语句都无法 ...

  10. Java之创建线程的方式三:实现Callable接口

    import java.util.concurrent.Callable;import java.util.concurrent.ExecutionException;import java.util ...