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 ...
随机推荐
- Git_使用GitHub
我们一直用GitHub作为免费的远程仓库,如果是个人的开源项目,放到GitHub上是完全没有问题的.其实GitHub还是一个开源协作社区,通过GitHub,既可以让别人参与你的开源项目,也可以参与别人 ...
- redis的搜索组件 redis-search4j
redis-search4j是一款基于redis的搜索组件. 特点 1.基于redis,性能高效 2.实时更新索引 3.支持Suggest前缀.拼音查找(AutoComplete功能) 4.支持单个或 ...
- hadoop 2.7.1 高可用安装部署
hadoop集群规划 目标:创建2个NameNode,做高可用,一个NameNode挂掉,另一个能够启动:一个运行Yarn,3台DataNode,3台Zookeeper集群,做高可用. 在hadoop ...
- MySQL性能诊断与调优 转
http://www.cnblogs.com/preftest/ http://www.highperfmysql.com/ BOOK LAMP 系统性能调优,第 3 部分: MySQL 服务 ...
- Entityframework:启用延时加载的主意事项(只为强化记忆)
Check List 无参的.高于私有访问级别的构造方法(经常忘记). 非封闭的类(默认的非封闭的). DbContext 配置要开启(默认是开启的). 因为我喜欢将类型设置为封闭的,提供有参数的构造 ...
- .NET:CLR via C#:Runtime Serialization
Making a Type Serializable The SerializableAttribute custom attribute may be applied to reference ty ...
- [翻译] 极具动感的 FRDLivelyButton
FRDLivelyButton https://github.com/sebastienwindal/FRDLivelyButton FRDLivelyButton is a simple UIBut ...
- [Android UI] Activity Maintheme (Android 解决程序启动时的黑屏问题)
<style name="MainTheme" parent="@android:style/Theme"> <item name=" ...
- Java IO 体系结构
参考文章地址: http://blog.csdn.net/oracle_microsoft/article/details/2634231 Java IO体系结构看似庞大复杂,其实有规律可循,要弄清楚 ...
- Paint、Canvas、Matrix使用解说(一、Paint)
username=tianjian4592">我正在參加 CSDN 2015博客之星评选 感恩分享活动,假设认为文章还不错,请投个票鼓舞下吧:http://vote.blog.csdn ...