题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2883

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.

题意描述:有n个人来烤肉店吃烤肉,每个人在si 时刻来ei 时刻离开并且点了ni 份,每份烤肉要烤到ti 个单位时间才算烤熟,烤肉店里可以同时烤m份。问是否有一种计划使得n个人都可以拿到自己的ni 份。
算法分析:这道题本身不是很难,网络流的模型也很常见,但是这道题中(si,ei)的时间跨度很大(1<=si<=ei<=1000000),所以不能把时间区间直接拆分开建立模型,这样顶点个数太多,会超时。这里,介绍一下学到的新技巧,我们可以把时间区间压缩:time[]里保存全部的si 和 ei ,这样time[i]-time[i-1]就表示一段时间区间了,如果这段时间区间在[si,ei]中,那么就把第 i 个人这个顶点和第 i 个时间区间相连接,然后,from->第 i 个人,第 i 个时间区间->to。这样,每一条s-t路径就表示一种烤肉的时间计划了。 
 #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 网络流的更多相关文章

  1. HDU 2883 kebab(最大流)

    HDU 2883 kebab 题目链接 题意:有一个烧烤机,每次最多能烤 m 块肉.如今有 n 个人来买烤肉,每一个人到达时间为 si.离开时间为 ei,点的烤肉数量为 ci,每一个烤肉所需烘烤时间为 ...

  2. 图论--网络流--最大流 HDU 2883 kebab(离散化)

    Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled ...

  3. hdu 2883 kebab(时间区间压缩 &amp;&amp; dinic)

    kebab Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  4. HDU 2883 kebab

    kebab Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 2883 ...

  5. F - kebab HDU - 2883 (最大流构图)

    Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on a long thin stic ...

  6. 网络流HDU 2883

    建图           源点  ->     每个人  ->           每段时间      ->      汇点 时间要离散化一下 分成一些时间段 权           ...

  7. kebab HDU - 2883(按时间段建点)

    题意: 有n个人去撸串,每个人都能决定自己的串上有几块肉,每一块肉都要花费一个单位时间才熟,烤炉一次能烤m块肉 给出每个人的起始时间.终止时间.要几串.每个串上有几块肉,问能否满足所有的人 (啥?题不 ...

  8. hdu 1733 分层网络流 ****

    题目大意:有一个类似于迷宫搜索的图,‘.’代表的是无人的路,'X'代表有人的点,'#'代表此点不可通过,'@'代表门口.每个位置每一秒钟只能站一个人,每个位置到上下左右点的时间为1,问你所有人能不能出 ...

  9. HDU 3452 Bonsai(网络流之最小割)

    题目地址:HDU 3452 最小割水题. 源点为根节点.再另设一汇点,汇点与叶子连边. 对叶子结点的推断是看度数是否为1. 代码例如以下: #include <iostream> #inc ...

随机推荐

  1. jquery.pagination +JSON 动态无刷新分页

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="SqlPage.aspx.cs& ...

  2. WPF—TreeView无限极绑定集合形成树结构

    1.如图所示:绑定树效果图 2.前台Xaml代码: <Window x:Class="WpfTest.MainWindow" xmlns="http://schem ...

  3. freefilesync 7 使用

    官方下载地址:http://www.freefilesync.org/download.php 1.打开FreeFileSync 设置左右的文件夹,设置过滤规则,设置同步方式(双向.单向),执行同步 ...

  4. html5制作一个时钟

    试着用html5写一个时钟 记得开始这个随笔是几天前,一直保存在草稿里面,一直感觉有个东西搁在在那里,所以今天熬夜也要写完这篇博客!!!哈哈...不多说来上代码和思路. --------------- ...

  5. php使用base64加密解密图片

    php使用base64加密解密图片的实例代码. 例子: <?php //文件名:base64.php $data="/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAB ...

  6. Ubuntu 下安装 Oracle JDK

    sudo add-apt-repository ppa:webupd8team/javasudo apt-get updatesudo apt-get install oracle-java8-ins ...

  7. 03-树2 List Leaves

    二叉树及其遍历 一遍AC,挺开心的hhh~ 简单讲下思路:叶子,顾名思义就是没有左右子树的结点.由于题目要求,叶子结点的输出顺序是从上往下,从左往右.所以用层序遍历法. 当然,这里先找到root树的根 ...

  8. linux的串口驱动分析

    1.串口驱动中的数据结构 • UART驱动程序结构:struct uart_driver  驱动 • UART端口结构: struct uart_port  串口 • UART相关操作函数结构: st ...

  9. Ubuntu下sqlite3的安装及使用

    Sqlite是一款轻型的数据库,实现了多数SQL-92标准,包括事务(原子性,一致性,隔离性和持久性 ACID),触发器与多数复杂查询.对于一个移动手持设备的应用开发者,Sqlite是居家旅行必备数据 ...

  10. hdu 5311 Hidden String

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Description Today is the 1st anniv ...