HDU 2883 kebab(最大流)
HDU 2883 kebab
题意:有一个烧烤机,每次最多能烤 m 块肉。如今有 n 个人来买烤肉,每一个人到达时间为 si。离开时间为 ei,点的烤肉数量为 ci,每一个烤肉所需烘烤时间为 di。注意一个烤肉能够切成几份来烤
思路:把区间每一个点存起来排序后。得到最多2 * n - 1个区间,这些就表示几个互相不干扰的时间,每一个时间内仅仅可能有一个任务器做。这样建模就简单了。源点连向汇点,容量为任务须要总时间,区间连向汇点,容量为区间长度。然后每一个任务假设包括了某个区间,之间就连边容量无限大。最后推断一下最大流是否等于总任务须要时间就可以
代码:
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; const int MAXNODE = 1005;
const int MAXEDGE = 200005; typedef int Type;
const Type INF = 0x3f3f3f3f; struct Edge {
int u, v;
Type cap, flow;
Edge() {}
Edge(int u, int v, Type cap, Type flow) {
this->u = u;
this->v = v;
this->cap = cap;
this->flow = flow;
}
}; struct Dinic {
int n, m, s, t;
Edge edges[MAXEDGE];
int first[MAXNODE];
int next[MAXEDGE];
bool vis[MAXNODE];
Type d[MAXNODE];
int cur[MAXNODE];
vector<int> cut; void init(int n) {
this->n = n;
memset(first, -1, sizeof(first));
m = 0;
}
void add_Edge(int u, int v, Type cap) {
edges[m] = Edge(u, v, cap, 0);
next[m] = first[u];
first[u] = m++;
edges[m] = Edge(v, u, 0, 0);
next[m] = first[v];
first[v] = m++;
} bool bfs() {
memset(vis, false, sizeof(vis));
queue<int> Q;
Q.push(s);
d[s] = 0;
vis[s] = true;
while (!Q.empty()) {
int u = Q.front(); Q.pop();
for (int i = first[u]; i != -1; i = next[i]) {
Edge& e = edges[i];
if (!vis[e.v] && e.cap > e.flow) {
vis[e.v] = true;
d[e.v] = d[u] + 1;
Q.push(e.v);
}
}
}
return vis[t];
} Type dfs(int u, Type a) {
if (u == t || a == 0) return a;
Type flow = 0, f;
for (int &i = cur[u]; i != -1; i = next[i]) {
Edge& e = edges[i];
if (d[u] + 1 == d[e.v] && (f = dfs(e.v, min(a, e.cap - e.flow))) > 0) {
e.flow += f;
edges[i^1].flow -= f;
flow += f;
a -= f;
if (a == 0) break;
}
}
return flow;
} Type Maxflow(int s, int t) {
this->s = s; this->t = t;
Type flow = 0;
while (bfs()) {
for (int i = 0; i < n; i++)
cur[i] = first[i];
flow += dfs(s, INF);
}
return flow;
} void MinCut() {
cut.clear();
for (int i = 0; i < m; i += 2) {
if (vis[edges[i].u] && !vis[edges[i].v])
cut.push_back(i);
}
}
} gao; const int N = 405; int n, m; struct Man {
int l, r;
} man[N]; int p[N], pn; int s, nu, e, t; int main() {
while (~scanf("%d%d", &n, &m)) {
gao.init(3 * n + 2);
pn = 0;
int sum = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &s, &nu, &e, &t);
man[i].l = s; man[i].r = e;
p[pn++] = s; p[pn++] = e;
sum += nu * t;
gao.add_Edge(0, i, nu * t);
}
sort(p, p + pn);
for (int i = 1; i < pn; i++)
gao.add_Edge(n + i, 3 * n + 1, (p[i] - p[i - 1]) * m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j < pn; j++) {
if (p[j - 1] > man[i].r) break;
if (man[i].l <= p[j - 1] && man[i].r >= p[j])
gao.add_Edge(i, j + n, INF);
}
}
printf("%s\n", gao.Maxflow(0, 3 * n + 1) == sum ? "Yes" : "No");
}
return 0;
}
HDU 2883 kebab(最大流)的更多相关文章
- 图论--网络流--最大流 HDU 2883 kebab(离散化)
Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled ...
- 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 2883(构图+最大流+压缩区间)
kebab Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 2883 kebab(时间区间压缩 && dinic)
kebab Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- F - kebab HDU - 2883 (最大流构图)
Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on a long thin stic ...
- kebab HDU - 2883(按时间段建点)
题意: 有n个人去撸串,每个人都能决定自己的串上有几块肉,每一块肉都要花费一个单位时间才熟,烤炉一次能烤m块肉 给出每个人的起始时间.终止时间.要几串.每个串上有几块肉,问能否满足所有的人 (啥?题不 ...
- HDU 3549 网络最大流再试
http://acm.hdu.edu.cn/showproblem.php?pid=3549 同样的网络最大流 T了好几次原因是用了cout,改成printf就A了 还有HDU oj的编译器也不支持以 ...
- Hdu 3605 Escape (最大流 + 缩点)
题目链接: Hdu 3605 Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...
随机推荐
- 【原】MyBatis执行DDL:create table,drop table等等
[前言] 对MyBatis一直停留在仅仅会用的阶段,常用的场景就是通过MyBatis对表数据进行DML(insert, delete, update等)操作,从来没有想过通过MyBatis对数据库 进 ...
- 重温PHP之冒泡排序
冒泡排序(Bubble Sort),是一种计算机科学领域的较简单的排序算法. 它重复地走访过要排序的元素列,依次比较两个相邻的元素,如果他们的顺序(如从大到小.首字母从A到Z)错误就把他们交换过来.走 ...
- Reverse Engineering the NC ECU (revisited) -- SH7508
http://forum.miata.net/vb/showthread.php?t=536601 Hey all! About 5 years ago, there was a great thre ...
- Remon Spekreijse CSerialPort用法
在程序中如果要用到多个串口,而且还要做很多复杂的处理,那么最好不用MSComm通讯控件,如果这时你还不愿意自己编写底层,就用这个类:CserialPort类.作者是 Remon Spekreijse ...
- 值得借鉴的Objective-C编程规范
Daniel's Objective-C Coding Style Guidelines http://google-styleguide.googlecode.com/svn/trunk/objcg ...
- 聊聊高并发(十四)理解Java中的管程,条件队列,Condition以及实现一个堵塞队列
这篇里面有一些主要的概念,理解概念是件有意义的事情,仅仅有理解概念才干在面对详细问题的时候找到正确的解决思路.先看一下管程的概念 第一次在书上看到管程这个中文名称认为非常迷糊,管程究竟是个什么东东,于 ...
- AutoMapper: Mapper.Initialize() 只能调用一次,Why?
最开始的代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- @private @protected @public
@private 作用范围仅仅在自身类 @protected 作用范围在自身类及继承自己的子类(默认属性) @public 在系统中的不论什么地方都能够使用
- sscanf,sprintf用法
#include<string.h> #include<stdio.h> int main() { ],sztime1[],sztime2[]; sscanf("12 ...
- bzoj 1565 [NOI2009]植物大战僵尸 解题报告
1565: [NOI2009]植物大战僵尸 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2161 Solved: 1000[Submit][Stat ...