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 ...
随机推荐
- 18 —— node 热部署工具 — supervisor /nodemon 。
1,全局安装: npm install -g supervisor 2,使用: —————————————————————————————— nodemon 和 supervisor 流程一致.
- C++基础--string转
有时候除了要将数值型转为string外,可能也需要将一些string转为数值型,这个时候也还是可以用sstream字符串流来实现,同时也可以用C++标准库得到函数来实现. 1.字符串流 这个时候使用i ...
- StringUtils.format用法
String.format()字符串常规类型格式化的两种重载方式 format(String format, Object… args) 新字符串使用本地语言环境,制定字符串格式和参数生成格式化的新字 ...
- 轻量级UILabel分段点击扩展更新啦
http://www.code4app.com/thread-31445-1-1.html Tag: 项目介绍: YBAttributeTextTapAction 一行代码添加文本点击事件 效果图 S ...
- 实验吧Web-易-简单的sql注入之3(报错的sql盲注之exp)
题目提示是报错注入,于是就用盲注技巧来注入. 这里注入时发现floor,extractvalue,updatexml被吃掉了,用exp可以注入成功.(记住大小写绕过等技巧) 1.爆库 ' or exp ...
- Linux下MSSQL部署
目前主要使用的red hat系列的linux版本,CentoS 7.X,MSSQL2017 微软官方说明地址:https://docs.microsoft.com/zh-cn/sql/linux/qu ...
- Mac Outlook 2016 无法打开会议室日历
问题:Mac Outlook 2016 无法打开会议室日历信息,报错截图如下: 解决方案: Set-MailboxFolderPermission -Identity XXX@xxx.com:\日历 ...
- .NETCore部署步骤
1.下载.NET CORE运行时 下载地址:https://dotnet.microsoft.com/download 2.windows安装下载的运行时 3.检查.是否安装成功 ,dotnet -- ...
- macOS下的播放器
很早前用 MplayerX, 现在不能用了, 找到一个替代品 https://iina.io/. 挺不错.
- elasticsearch + springboot 整合
https://blog.csdn.net/chengyuqiang/article/details/102938266 https://blog.csdn.net/chengyuqiang/arti ...