题目大意:有n个城市m条航线。给出每条航线的出发地,目的地,座位数,起飞时间和到达时间(所给形式为HHMM。记得转化),再给出城市A和B。和到达城市B的最晚时间。如今问一天内最多有多少人能从A飞到B,能够在其它城市中转

解题思路:将飞机票拆点,拆成i–>i + m,容量为座位数。

接着推断一下。航线之间的连线

假设航线的起点是A的话,那么就和超级源点相连,容量为INF

假设航线的终点是B且到达时间小于等于最晚时间。那么连线,容量为INF

假设航线i的终点和航线j的起点同样。且航线i的到达时间+30<=航线j的起始时间,那么连线。容量为INF

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iostream>
using namespace std;
#define N 10010
#define INF 0x3f3f3f3f struct Edge{
int from, to, cap, flow;
Edge() {}
Edge(int from, int to, int cap, int flow) : from(from), to(to), cap(cap), flow(flow) {}
}; struct Dinic{
int n, m, s, t;
vector<Edge> edges;
vector<int> G[N];
bool vis[N];
int d[N], cur[N]; void init(int n) {
this->n = n;
for (int i = 0; i <= n; i++) {
G[i].clear();
}
edges.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));
int m = edges.size();
G[from].push_back(m - 2);
G[to].push_back(m - 1);
} bool BFS() {
memset(vis, 0, sizeof(vis));
queue<int> Q;
Q.push(s);
vis[s] = 1;
d[s] = 0; while (!Q.empty()) {
int u = Q.front();
Q.pop();
for (int i = 0; i < G[u].size(); i++) {
Edge &e = edges[G[u][i]];
if (!vis[e.to] && e.cap > e.flow) {
vis[e.to] = true;
d[e.to] = d[u] + 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[x] + 1 == d[e.to] && (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 Maxflow(int s, int t) {
this->s = s; this->t = t;
int flow = 0;
while (BFS()) {
memset(cur, 0, sizeof(cur));
flow += DFS(s, INF);
}
return flow;
}
}; Dinic dinic;
#define M 5100
#define S 160
int n, m, source, sink, Time;
int num[S];
map<string, int> Map;
struct Node {
int u, v, c, s, t;
}node[M]; int getTime(string T) {
int a = (T[0] - '0') * 10 + (T[1] - '0');
int b = (T[2] - '0') * 10 + (T[3] - '0');
return a * 60 + b;
} void solve() {
Map.clear();
int cnt = 3;
string a, b, s, t; cin >> a >> b >> s >> m;
Map[a] = 1; Map[b] = 2;
Time = getTime(s); memset(num, 0, sizeof(num));
source = 0; sink = 2 * m + 1;
dinic.init(sink); for (int i = 1; i <= m; i++) {
cin >> a >> b >> node[i].c >> s >> t; if (!Map[a]) Map[a] = cnt++;
if (!Map[b]) Map[b] = cnt++; node[i].u = Map[a];
node[i].v = Map[b];
node[i].s = getTime(s);
node[i].t = getTime(t); num[node[i].u]++; num[node[i].v]++;
dinic.AddEdge(i, i + m, node[i].c);
} if (!num[1] || !num[2]) {
printf("0\n");
return ;
} for (int i = 1; i <= m; i++) {
int u = node[i].u, v = node[i].v;
if (u == 1) dinic.AddEdge(source, i, INF);
if (v == 2 && node[i].t <= Time) dinic.AddEdge(i + m, sink, INF); for (int j = 1; j <= m; j++) {
if (i == j) continue;
if (v != node[j].u) continue;
if (node[i].t + 30 <= node[j].s) dinic.AddEdge(i + m, j, INF); }
}
int ans = dinic.Maxflow(source, sink);
printf("%d\n", ans);
} int main() {
while (scanf("%d\n", &n) != EOF) solve();
return 0;
}

UVA - 1161 Objective: Berlin(最大流+时序模型)的更多相关文章

  1. UVa 1161 Objective: Berlin (最大流)

    题意:给定一些航班,每个航班有人数,和起始终止时间,每次转机要花半小时,问限制时间内最多能有多少人从起始城市到终点城市. 析:差不多是裸板网络流的最大流问题,把每个航班都拆成两个点,这两个点之间连接一 ...

  2. UVALive 3645 Objective: Berlin(最大流 :时序模型)

    题意:已知n(n <= 150)个城市和m(m <= 5000)个航班,每个航班有出发地.到达地.乘坐人数.起飞时间和降落时间(时间用时和分表示),求从一个指定城市出发,去往另一个指定城市 ...

  3. UVaLive 3645 Objective: Berlin (最大流)

    题意:有n个城市,m条航班.已知每条航班的起点和终点,还有每条航班的载客量.出发时间.到达时间.并且要求在任何一个城市(起点.终点除外)都至少要有30分钟的中转时间,求起点到终点的最大客流量. 析:把 ...

  4. 应用层级时空记忆模型(HTM)实现对实时异常流时序数据检测

    应用层级时空记忆模型(HTM)实现对实时异常流时序数据检测 Real-Time Anomaly Detection for Streaming Analytics Subutai Ahmad SAHM ...

  5. Verilog篇(四)时序模型

    时序模型:仿真器的时间推进模型,它反映了推进仿真时间和调度事件的方式. 1)门级时序模型:适用于分析所有的连续赋值语句,过程连续赋值语句,门级原语,用户自定义原语. 特点:任意时刻,任意输入变化都将重 ...

  6. Keras 时序模型

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Thinking_boy1992/article/details/53207177 本文翻译自 时序模 ...

  7. EGADS介绍(二)--时序模型和异常检测模型算法的核心思想

    EDADS系统包含了众多的时序模型和异常检测模型,这些模型的处理会输入很多参数,若仅使用默认的参数,那么时序模型预测的准确率将无法提高,异常检测模型的误报率也无法降低,甚至针对某些时间序列这些模型将无 ...

  8. UVALive-3645 Objective: Berlin (最大流:时序模型)

    题目大意:有n个城市,m条航班.已知每条航班的起点和终点,还有每条航班的载客量.出发时间.到达时间.并且要求在任何一个城市(起点.终点除外)都至少要有30分钟的中转时间,求起点到终点的最大客流量. 题 ...

  9. UVa1161 Objective: Berlin(最大流)

    题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

随机推荐

  1. es6 -- set 数据结构

    ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set 本身是一个构造函数,用来生成 Set 数据结构. const s = new Set(); [2, 3 ...

  2. HTTP服务器状态码定义

    HTTP服务器状态代码定义 1.1 消息1xx(Informational 1xx) 该类状态代码用于表示临时回应.临时回应由状态行(Status-Line)及可选标题组成, 由空行终止.HTTP/1 ...

  3. $.each(data, function (index, value) { })的用法;json和list<>的互相转换

    在json中常常碰到这样的代码: jquery $.each(data, function (index, value) {    }) 遍历处理data,可以是数组.DOM.json等,取决于直接给 ...

  4. FormatMessage函数的使用方法

    使用FormatMessage时假设对一些參数不细致研究.那么就会出错误.首先说下这个函数 1 函数描写叙述 DWORD WINAPI FormatMessage( _In_ DWORD dwFlag ...

  5. 高速数论变换(NTT)

    今天的A题.裸的ntt,但我不会,于是白送了50分. 于是跑来学一下ntt. 题面非常easy.就懒得贴了,那不是我要说的重点. 重点是NTT,也称高速数论变换. 在非常多问题中,我们可能会遇到在模意 ...

  6. php实现希尔排序(总结)

    php实现希尔排序(总结) 一.总结 1.希尔排序的算法思路:分组排序, 缩小增量排序,插入排序 2.算法思路: 循环非常好写 有几次gap:log2(n) 每次gap有几组:gap组 每组有几个元素 ...

  7. 5.Node.js 安装配置

    转自:http://www.runoob.com/nodejs/nodejs-tutorial.html Node.js安装包及源码下载地址为:https://nodejs.org/en/downlo ...

  8. JS实现文件另存为

    JS实现文件另存为 //下载平面图 function downPlan() { var oPop = window.open(src, "", "width=1, hei ...

  9. Day4上午解题报告

    预计分数:50 +0+0=50 实际分数:50+0+10=60 毒瘤出题人,T3不给暴力分 (*  ̄︿ ̄) T1 https://www.luogu.org/problem/show?pid=T155 ...

  10. webstorm快捷键(觉得有用,喜欢的话可以保存收藏哦)

    Ctrl+/ 或 Ctrl+Shift+/------------------------->>注释(// 或者/*…*/ ) Ctrl+X删除行 Ctrl+D复制行 Ctrl+G查找行 ...