题目大意:有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. 54.nodejs nodemailer不兼容

    转自:https://blog.csdn.net/q36835109/article/details/53067917 注:由于本人使用最新版本的nodemailer不兼容,所以目前使用的是0.7.1 ...

  2. Kinect 开发 —— 骨骼追踪进阶(上)

    Kinect传感器核心只是发射红外线,并探测红外光反射,从而可以计算出视场范围内每一个像素的深度值.从深度数据中最先提取出来的是物体主体和形状,以及每一个像素点的游戏者索引信息.然后用这些形状信息来匹 ...

  3. bash命令集---文件的操作

    git bash命令集: clear:清除窗口中的内容 ls touch cat more head tail mv cp rm diff chmod gzip gunzip gzcat lpr lp ...

  4. POJ 2981 Strange Way to Express Integers 模线性方程组

    http://poj.org/problem?id=2891 结果看了半天还是没懂那个模的含义...懂了我再补充... 其他的思路都在注释里 /********************* Templa ...

  5. layui动态无限极菜单

    ajax加jQuery实现 效果图 参考文章:https://www.wanpishe.top/detail?blogId=644aa177-9795-456a-8090-ee1264bf5d9d

  6. logout命令用于退出当前登录的Shell

    logout命令用于退出当前登录的Shell

  7. POJ 1442 Black Box treap求区间第k大

    题目来源:POJ 1442 Black Box 题意:输入xi 输出前xi个数的第i大的数 思路:试了下自己的treap模版 #include <cstdio> #include < ...

  8. 关于结构体COORD介绍

    COORD是windows API中定义的一种结构,表示一个字符在控制台屏幕上的坐标.其定义为: typedef struct _COORD { SHORT X; // horizontal coor ...

  9. centos7 Another app is currently holding the yum lock; waiting for it to exit...

    解决方法:rm -rf /var/run/yum.pid 来强行解除锁定,然后你的yum就可以运行了

  10. win7旗舰版怎么降级到专业版

    一.操作准备及注意事项 1.UltraISO光盘制作工具9.5 2.备份C盘及桌面文件 二.win7旗舰版改成专业版的步骤 1.当前系统为Win7 SP1 64位旗舰版: 2.按Win+R打开运行,输 ...