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 ...
随机推荐
- BZOJ:1927: [Sdoi2010]星际竞速
题解:最小费用流+二分图模型: 左边表示出这个点,右边表示入这个点: #include<iostream> #include<cstdio> #include<cstri ...
- uboot 学习笔记
ram 初始化: 在 start.S 中, bl cpu_init_crit 这句,在 tq2440 中是直接调用,在韦东山里面是通过和 TEXT_BASE 进行比较,如果从 RAM 中运行就不进行 ...
- gentoo emby-server
最近想用 emby-server + kodi 打造家庭播放平台, 在 gentoo 上面先尝试安装配置 emby-server. 首先, 使用 megacoffee 这个 overlay, 这个上面 ...
- css3 实现渐变边框
(1)一个渐变的底边线border:1px solid transparent;border-image: -webkit-linear-gradient(right, #FF9848,#FF2A2B ...
- 开发app
开始学习apicloud开发流程 第一天 了解平台应用 第二天看视频进行学习软件开发的过程 第三天学习编码html 第四天编写了一副框架 第五天完成扫一i扫
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- jvm调优原则
合理规划jvm性能调优 JVM性能调优涉及到方方面面的取舍,往往是牵一发而动全身,需要全盘考虑各方面的影响.但也有一些基础的理论和原则,理解这些理论并遵循这些原则会让你的性能调优任务将会更加轻松.为了 ...
- k8s pod.yml解释
apiVersion: v1kind: Podmetadata: name: yueying namespace: kube-public labels: name: testpodssp ...
- win10编译libpng
libpng在windows的编译. ligpng的官网介绍如下: libpng is the official PNG reference library. It supports almost a ...
- 如何在MySQL目录下找到my.ini
1. 打开ProgramData目录 2. 进入目录C:\ProgramData\MySQL\MySQL Server 8.0