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. SpringAOP 使用注解的简单使用

    1. 导入jar包 /SpringAOPmy/lib/com.springsource.net.sf.cglib-2.2.0.jar/SpringAOPmy/lib/com.springsource. ...

  2. Linux Shell编程case语句

    http://blog.csdn.net/dreamtdp/article/details/8048720 case语句适用于需要进行多重分支的应用情况. case分支语句的格式如下: case $变 ...

  3. LeetCode | No.1 两数之和

    题目描述: Given an array of integers, return indices of the two numbers such that they add up to a speci ...

  4. No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing inst

    今日遇到一个报错如下: No enclosing instance of type test is accessible. Must qualify the allocation with an en ...

  5. HDU_2255 二分图最佳完美匹配 KM匈牙利算法

    一开始还没看懂这个算法,后来看了陶叔去年的PPT的实例演示才弄懂 用一个lx[]和ly[]来记录X和Y集合中点的权值,有个定理是 lx[i]+ly[j]==w[i][j](边权值) 则该点是最佳匹配, ...

  6. adfs环境安装

    安装文档参考: https://docs.microsoft.com/zh-cn/windows-server/identity/ad-fs/deployment/set-up-the-lab-env ...

  7. [ACTF2020 新生赛]Include

    0x00 知识点 本地文件包含 ?file=php://filter/read/convert.base64-encode/resource=index.php ?file=php://filter/ ...

  8. kube-controller-manager配置详解

    KUBE_MASTER="--master=http://10.83.52.137:8080" KUBE_CONTROLLER_MANAGER_ARGS=" "

  9. mysql 去除重复 Select中DISTINCT关键字的用法(查询两列,只去掉重复的一列)

    在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的 ...

  10. Java自学-集合框架 聚合操作

    聚合操作 步骤 1 : 聚合操作 JDK8之后,引入了对集合的聚合操作,可以非常容易的遍历,筛选,比较集合中的元素. 像这样: String name =heros .stream() .sorted ...