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;
}

最新文章

  1. C++基础知识面试精选100题系列(11-20题)[C++ basics]
  2. PHP-----练习-------租房子-----增删改查,多条件查询
  3. 搭建测试环境——针对S3C6410开发板
  4. CF 86D Powerful array 【分块算法,n*sqrt(n)】
  5. android startActivityForResult(Intent intent, int requestCode) 整理与总结! .
  6. 使用HttpServletRequestWrapper在filter修改request参数
  7. SQL Server Insert操作中的锁
  8. 4GB内存原32位系统(x86)取舍问题,显卡共享内存Win8.1完全不用担心
  9. HashMap的hash原理
  10. Eclispe 错误:找不到或无法加载加载主类
  11. binary and out mode to open a file
  12. POI2015 解题报告
  13. 大数据权限管理工具 Apache Ranger 初识
  14. [NOIP 2015TG D1T3] 斗地主
  15. Docker Swarm Mode无法增加管理节点
  16. Intellij IDEA 将工程转换成maven工程 详解
  17. Speeding up image loading in WPF using thumbnails
  18. eclipse两种注释的快捷键
  19. BeanPostProcessor的五大接口
  20. PCA算法和SVD

热门文章

  1. ActiveMQ Cluster (ActiveMQ 集群) 配置
  2. LINUX mysql 源码安装
  3. 我对NHibernate的感受(4):令人欣喜的Interceptor机制
  4. 【Nginx】ngx_event_core_module模块
  5. C#使用反射加载多个程序集
  6. Android中UI设计的一些技巧!!!
  7. jsp下Kindeditor环境搭建
  8. 使用开源库 SDWebImage 异步下载缓存图片(持续更新)
  9. [MAC OS] 常用工具
  10. scala 学习笔记十 一 伴生对象