Problem Description

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.

 Input
There 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
 Output
If 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
这个题就是基本的最大流,怎么建图,源点到每个人建边,流量设置为点羊肉串数量。然后每个人到他那个时间段的每一个边都设流量为INF,然后,时间点到汇点的边设置为M即,烤炉最多一次考多少串串。但是这里要考虑到点的范围1000000,这样建图真的会超时,我看了RQ的博客,看到了这里是可以离散化建图,就是说,将每个点看成一段时间的集合,如过时间有交叉就要把那段时间单独处理,这样它覆盖了多少点,就有多少个M然后最大流。 
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector>
#define INF 1e9
using namespace std;
const int maxn=600+5; struct Edge
{
int from,to,cap,flow;
Edge(){}
Edge(int f,int t,int c,int fl):from(f),to(t),cap(c),flow(fl){}
}; struct Dinic
{
int n,m,s,t;
vector<Edge> edges;
vector<int> G[maxn];
int d[maxn];
int cur[maxn];
bool vis[maxn]; void init(int n,int s,int t)
{
this->n=n, this->s=s, this->t=t;
edges.clear();
for(int i=0;i<n;++i) G[i].clear();
} void AddEdge(int from,int to,int cap)
{
edges.push_back(Edge(from,to,cap,0));
edges.push_back(Edge(to,from,0,0));
m = edges.size();
G[from].push_back(m-2);
G[to].push_back(m-1);
} bool BFS()
{
queue<int> Q;
memset(vis,0,sizeof(vis));
vis[s]=true;
d[s]=0;
Q.push(s);
while(!Q.empty())
{
int x=Q.front(); Q.pop();
for(int i=0;i<G[x].size();++i)
{
Edge &e=edges[G[x][i]];
if(!vis[e.to] && e.cap>e.flow)
{
vis[e.to]=true;
d[e.to]=d[x]+1;
Q.push(e.to);
}
}
}
return vis[t];
} int DFS(int x,int a)
{
if(x==t || a==0) return a;
int flow=0,f;
for(int& i=cur[x];i<G[x].size();++i)
{
Edge &e=edges[G[x][i]];
if(d[e.to]==d[x]+1 && (f=DFS(e.to,min(a,e.cap-e.flow) ) )>0)
{
e.flow +=f;
edges[G[x][i]^1].flow -=f;
flow +=f;
a -=f;
if(a==0) break;
}
}
return flow;
} int max_flow()
{
int ans=0;
while(BFS())
{
memset(cur,0,sizeof(cur));
ans += DFS(s,INF);
}
return ans;
}
}DC; int N,M;
int s[maxn],n[maxn],e[maxn],t[maxn];
int time[maxn];
int full_flow; int main()
{
while(scanf("%d%d",&N,&M)==2)
{
full_flow=0;
int cnt=0;
for(int i=1;i<=N;i++)
{
scanf("%d%d%d%d",&s[i],&n[i],&e[i],&t[i]);
time[cnt++]=s[i];
time[cnt++]=e[i];
full_flow += n[i]*t[i];
}
sort(time,time+cnt);
cnt = unique(time,time+cnt)-time;//去重
int src=0,dst=N+cnt+1;
DC.init(N+cnt+2,src,dst); for(int i=1;i<=N;i++) DC.AddEdge(src,i,n[i]*t[i]);
for(int i=1;i<=cnt-1;++i)
{
DC.AddEdge(N+i,dst,(time[i]-time[i-1])*M);
for(int j=1;j<=N;++j)
if(s[j]<=time[i-1] && time[i]<=e[j])
DC.AddEdge(j,N+i,INF);
}
printf("%s\n",DC.max_flow()==full_flow?"Yes":"No");
}
return 0;
}

图论--网络流--最大流 HDU 2883 kebab(离散化)的更多相关文章

  1. 图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)

    Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...

  2. HDU 2883 kebab(最大流)

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

  3. hdu 2883 kebab 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2883 Almost everyone likes kebabs nowadays (Here a ke ...

  4. 图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)

    Problem Description Gabiluso is one of the greatest spies in his country. Now he's trying to complet ...

  5. HDU 2883 kebab

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

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

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

  7. 图论--网络流--最大流--POJ 3281 Dining (超级源汇+限流建图+拆点建图)

    Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, an ...

  8. 网络流 最大流HDU 3549

    //////////在这幅图中我们首先要增广1->2->4->6,这时可以获得一个容量为2的流,但是如果不建立4->2反向弧的话,则无法进一步增广,最终答案为2,显然是不对的, ...

  9. 网络流(最大流) HDU 1565 方格取数(1) HDU 1569 方格取数(2)

      HDU 1565 方格取数(1) 给你一个n*n的格子的棋盘,每个格子里面有一个非负数.从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的 ...

随机推荐

  1. echarts以地图形式显示中国疫情情况实现点击省份下钻

    首先要导入对应的包.下钻用到各个省份的json文件等内容导入之后进行相关的操作. 首先是从数据库中读取相应的数据文件.通过list方式.只有在ser出转化为json文件.在jsp页面通过ajax来进行 ...

  2. android之间的各项信息传输类型

    首先是activity想fragment怎样动态的传输数据: 一:activity与fragment之间进行数据传递是,在Activity中将要传递的数据封装在一Bundle中,使用setArgume ...

  3. Linux强大屏幕截图方法,理论能截取任何图形界面,包括登录界面

    众所周知,屏幕截图可以使用“Print Screen”按键,但是,此按键的响应是靠系统的后台服务实现的,Linux在某些场景下,是不响应此按键的. 这里介绍一种更强大的截图方法,它是靠转储X图形环境的 ...

  4. MySQL入门,第三部分,学会添加删除数据库

    一.建立数据库 create database [if not exists] database_name [create_specification] 注意: 1.if not exists === ...

  5. Java第十四天,集合、迭代器的使用

    集合 集合框架 一.Collection 1.定义方法: Collection<E> obj = new Collection子类<>(); 因为Collection是一个抽象 ...

  6. Python高级特性-迭代器和生成器

    迭代器 Python中可迭代对象(iterable)通俗指可直接作用与For循环的数据对象,如Python中的集合数据类型,字符串(str),列表(list),元组(tuple),集合(set),字典 ...

  7. Redis cluster集群配置教程

    这里建议大家安装4.0.9版本的 1.打开Centos虚拟机,登陆. 2.通过WinSCP把Redis集群tar包上传到虚拟机里的目录里,我的目录是 /usr/local 这里我已经上传过了并解压了, ...

  8. SpringBoot实现图片上传demo&Nginx进行代理显示

    公司项目需要一个图片上传的功能,就图片能上传到服务器(公司用的windows服务器),然后nginx能进行代理访问到就行了,先简单介绍一下nginx,然后再来实现功能. 一.nginx简介 Nginx ...

  9. 对于之间不平凡的我,为什么会选择IT!(上)

    我相信有很多小伙伴看了我发布的文章后,不知道对大家有无启发,在这里我都非常感谢大家的收看,因为现在收疫情影响,我也看到很多朋友私信我,看你经历这么多是经历了什么,如果大家在上一篇发现的时候会看见我父亲 ...

  10. FreeRTOS操作系统工程建立和操作系统的概念

    一.建立工程步骤如下: 二.详细步骤流程如下: 1.新建工程文件夹,然后在里面建立如下几个文件: 2.使用keil5建立工程: a.建立工程: b.添加内核文件: 3.建立文件分组: 4.创建main ...