hdu 2883 kebab 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define inf 0x7fffffff
using namespace std;
const int maxn=+;
const int M = ; int n,m,from,to;
int d[maxn];
struct node
{
int v,flow;
int next;
}edge[M*];
int head[maxn],edgenum; void add(int u,int v,int flow)
{
edge[edgenum].v=v ;edge[edgenum].flow=flow ;
edge[edgenum].next=head[u];
head[u]=edgenum++; edge[edgenum].v=u ;edge[edgenum].flow=;
edge[edgenum].next=head[v];
head[v]=edgenum++;
} int bfs()
{
memset(d,,sizeof(d));
d[from]=;
queue<int> Q;
Q.push(from);
while (!Q.empty())
{
int u=Q.front() ;Q.pop() ;
for (int i=head[u] ;i!=- ;i=edge[i].next)
{
int v=edge[i].v;
if (!d[v] && edge[i].flow>)
{
d[v]=d[u]+;
Q.push(v);
if (v==to) return ;
}
}
}
return ;
} int dfs(int u,int flow)
{
if (u==to || flow==) return flow;
int cap=flow;
for (int i=head[u] ;i!=- ;i=edge[i].next)
{
int v=edge[i].v;
if (d[v]==d[u]+ && edge[i].flow>)
{
int x=dfs(v,min(cap,edge[i].flow));
edge[i].flow -= x;
edge[i^].flow += x;
cap -= x;
if (cap==) return flow;
}
}
return flow-cap;
} int dinic()
{
int sum=;
while (bfs()) sum += dfs(from,inf);
return sum;
} int main()
{
while (scanf("%d%d",&n,&m)!=EOF)
{
memset(head,-,sizeof(head));
edgenum=;
int s[],q[],e[],t[];
int time[maxn],cnt=;
memset(time,,sizeof(time));
int sum=;
for (int i= ;i<=n ;i++)
{
scanf("%d%d%d%d",&s[i],&q[i],&e[i],&t[i]);
sum += q[i]*t[i];
time[cnt++]=s[i];
time[cnt++]=e[i];
}
sort(time+,time+cnt);
int c=;
for (int i= ;i<cnt ;i++)
{
if (time[c] != time[i])
time[++c]=time[i];
}
from=n+c+;
to=from+;
for (int i= ;i<=n ;i++)
add(from,i,q[i]*t[i]);
for (int i= ;i<=c ;i++)
{
add(n+i,to,m*(time[i]-time[i-]));
for (int j= ;j<=n ;j++)
{
if (s[j]<=time[i-] && time[i]<=e[j])
add(j,n+i,inf);
}
}
if (sum==dinic()) printf("Yes\n");
else printf("No\n");
}
return ;
}
hdu 2883 kebab 网络流的更多相关文章
- HDU 2883 kebab(最大流)
HDU 2883 kebab 题目链接 题意:有一个烧烤机,每次最多能烤 m 块肉.如今有 n 个人来买烤肉,每一个人到达时间为 si.离开时间为 ei,点的烤肉数量为 ci,每一个烤肉所需烘烤时间为 ...
- 图论--网络流--最大流 HDU 2883 kebab(离散化)
Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled ...
- hdu 2883 kebab(时间区间压缩 && dinic)
kebab Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDU 2883 kebab
kebab Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 2883 ...
- F - kebab HDU - 2883 (最大流构图)
Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on a long thin stic ...
- 网络流HDU 2883
建图 源点 -> 每个人 -> 每段时间 -> 汇点 时间要离散化一下 分成一些时间段 权 ...
- kebab HDU - 2883(按时间段建点)
题意: 有n个人去撸串,每个人都能决定自己的串上有几块肉,每一块肉都要花费一个单位时间才熟,烤炉一次能烤m块肉 给出每个人的起始时间.终止时间.要几串.每个串上有几块肉,问能否满足所有的人 (啥?题不 ...
- hdu 1733 分层网络流 ****
题目大意:有一个类似于迷宫搜索的图,‘.’代表的是无人的路,'X'代表有人的点,'#'代表此点不可通过,'@'代表门口.每个位置每一秒钟只能站一个人,每个位置到上下左右点的时间为1,问你所有人能不能出 ...
- HDU 3452 Bonsai(网络流之最小割)
题目地址:HDU 3452 最小割水题. 源点为根节点.再另设一汇点,汇点与叶子连边. 对叶子结点的推断是看度数是否为1. 代码例如以下: #include <iostream> #inc ...
随机推荐
- asp.net跨页面传值
a.aspx.cs //获取a中的id HttpCookie objCookie = new HttpCookie("myCookie", id); Response.Cookie ...
- 输出内容(document.write)四种写法
第一种:输出内容用""括起,直接输出""号内的内容 <script type="text/javascript"> docume ...
- Windows Server 2003开机自动启动MySQL服务设置方法
Windows Server 2003开机自动启动MySQL服务设置方法 发布时间:2014-12-19 更新时间:2014-12-24 来源:网络 作者:eaglezhong 关键词: 2003 e ...
- 学习simple.data之基础篇
simple.data是一个轻量级的.动态的数据访问组件,支持.net4.0. 1.必须条件和依赖性: v4.0 or greater of the .NET framework, or v2.10 ...
- python 内存管理
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 语言的内存管理是语言设计的一个重要方面.它是决定语言性能的重要因素.无论是C语言的 ...
- [转载]--用Python 自动安装软件
脚本使用了 Python 2.3 + Com 对象,所以你的系统必须安装Python2.3或更高版本同时必须安装 Mark Hammond's Win32all 模块 (特别感谢Mark Hamm ...
- 苹果HomeKit如何牵动全国智能硬件格局
苹果HomeKit如何牵动全国智能硬件格局 2014-06-23 15:48 发表 系统分类:消费电子 自定义分类:默认 标签:智能家居 苹果在6月的WWDC开发者大会上发布了包括 ...
- Android内存管理机制
相信一步步走过来的Android从业者,每个人都会遇到OOM的情况.如何避免和防范OOM的出现,对于每一个程序员来说确实是一门必不可少的能力. 今天我们就谈谈在Android平台下内存的管理之道,开始 ...
- 关于跨域响应头Access-Control-Allow-Headers的一些说明
在跨域PreFlight的过程中,Options请求会返回一个响应头,如果服务器返回了这个响应头,则允许用户发起GET.POST.HEAD这三个简单方法的请求,如需发起其他形式的请求则需要显示地在 A ...
- UI进阶 即时通讯之卸载Openfire
首先,确保你已经关掉了openfire打开终端 (在应用程序-->实用工具-->)输入以下命令sudo rm -rf /Library/PreferencePanes/Openfire.p ...