F - kebab HDU - 2883 (最大流构图)
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 (最大流构图)的更多相关文章
- kebab HDU - 2883(按时间段建点)
题意: 有n个人去撸串,每个人都能决定自己的串上有几块肉,每一块肉都要花费一个单位时间才熟,烤炉一次能烤m块肉 给出每个人的起始时间.终止时间.要几串.每个串上有几块肉,问能否满足所有的人 (啥?题不 ...
- HDU 2883 kebab(最大流)
HDU 2883 kebab 题目链接 题意:有一个烧烤机,每次最多能烤 m 块肉.如今有 n 个人来买烤肉,每一个人到达时间为 si.离开时间为 ei,点的烤肉数量为 ci,每一个烤肉所需烘烤时间为 ...
- HDU 1532 最大流入门
1.HDU 1532 最大流入门,n个n条边,求第1点到第m点的最大流.只用EK做了一下. #include<bits/stdc++.h> using namespace std; #pr ...
- 网络流 - 最大流构图入门 bzoj 1305
一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会“单向喜欢”).每个男孩 ...
- 图论--网络流--最大流 HDU 2883 kebab(离散化)
Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled ...
- hdu 2883(构图+最大流+压缩区间)
kebab Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 2883 kebab
kebab Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 2883 ...
- hdu 2883 kebab 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2883 Almost everyone likes kebabs nowadays (Here a ke ...
- hdu 2686&&hdu 3376(拆点+构图+最小费用最大流)
Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
随机推荐
- 了解java常用框架
今天我看了一点看起来比较片面的东西,java常用基本床架,并且在网上搜了相关的知识和概括总结,用来继续后期的学习: 1.struts2框架,这是最经典的框架(可以说没有“之一”).可以帮你快速搭建出一 ...
- JS最新最细面试题
转之:https://www.jianshu.com/p/f1f39d5b2a2e 1. javascript的typeof返回哪些数据类型. 答案:string,boolean,number,und ...
- exgcd详解
注:本文中所有 \(\%\) 号均表示取模, \(gcd(a,b)\) 表示 \(a\) 和 \(b\) 的最大公因数 1.exgcd是什么? exgcd大名扩展欧几里得算法,用来求形如 \(gcd( ...
- mysql自增长字段设置
mysql版本:5.7.27 说明:表中只能设置一个自增长字段[主键.索引(其他普通字段不行))] 设置自增长开始值: ALTER TABLE table_name AUTO_INCREMENT=10 ...
- 1, vm: PropTypes.instanceOf(VM).isRequired
子模块的文件引入父工程对象时,出现红色warning,提示传入的对象类型不是所要求的类型. 思路是父工程引用的JS包和子模块使用的包不是同一个包,解决办法是父工程和子工程都使用同一个包. resolv ...
- django-替代为自定义的User model
https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model Subs ...
- 一天一个设计模式——模板方法(Template Method)模式
一.模式说明 现实世界中的模板是用于将事物的结构规律予以固定化.标准化的成果,它体现了结构形式的标准化.例如镂空文字印刷的模板,通过某个模板印刷出来的文字字体大小都是一模一样,但是具体使用什么材质的颜 ...
- Q9:Palindrome Number
9. Palindrome Number 官方的链接:9. Palindrome Number Description : Determine whether an integer is a pali ...
- git push的时候.gitignore不起作用的解决方法
问题的原因 这是因为在你添加.gitignore之前已经进行过push操作,有些文件已经纳入版本管理了. 解决方法 我们就应该先把本地缓存删除,然后再进行git的push,这样就不会出现忽略的文件了. ...
- 《打造扛得住的MySQL数据库架构》第4章 MySQL数据库结构优化
4-1 数据库结构优化介绍 良好的数据库逻辑设计和物理设计是数据库获得高性能的基础. 1.减少不必要的数据冗余. 2.尽量避免数据维护中出现更新,插入和删除异常. 插入异常:如果表中的某个实体随着另一 ...