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

析:把每个航线看成一个点,然后拆成两个点,然后如果两个航线能够到达,并且时间不超的话,就连一条边,然后加一个源点和汇点,分别向开始和结束城市进行连线,容量无限大。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-3;
const int maxn = 1e4 + 10;
const int maxm = 1e7 + 10;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} struct Edge{
int from, to, cap, flow;
};
struct Dinic{
int n, m, s, t;
vector<Edge> edges;
vector<int> G[maxn];
int d[maxn];
bool vis[maxn];
int cur[maxn]; void init(int n){
this-> n = n;
for(int i = 0; i < n; ++i) G[i].cl;
edges.cl;
} void addEdge(int from, int to, int cap){
edges.pb((Edge){from, to, cap, 0});
edges.pb((Edge){to, from, 0, 0});
m = edges.sz;
G[from].pb(m - 2);
G[to].pb(m - 1);
} bool bfs(){
ms(vis, 0); vis[s] = 1; d[s] = 0;
queue<int> q; q.push(s); while(!q.empty()){
int u = q.front(); q.pop();
for(int i = 0; i < G[u].sz; ++i){
Edge &e = edges[G[u][i]];
if(!vis[e.to] && e.cap > e.flow){
vis[e.to] = 1;
d[e.to] = d[u] + 1;
q.push(e.to);
}
}
}
return vis[t];
} int dfs(int u, int a){
if(u == t || a == 0) return a;
int flow = 0, f;
for(int &i = cur[u]; i < G[u].sz; ++i){
Edge &e = edges[G[u][i]];
if(d[e.to] == d[u] + 1 && (f = dfs(e.to, min(a, e.cap-e.flow))) > 0){
e.flow += f;
edges[G[u][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()){ ms(cur, 0); flow += dfs(s, INF); }
return flow;
}
}; Dinic dinic;
map<string, int> mp; int ID(const string &s){
if(mp.count(s)) return mp[s];
return mp[s] = mp.sz;
} struct Fly{
int s, t, st, tt;
};
Fly fly[maxn]; int main(){
ios::sync_with_stdio(false);
while(cin >> n){
mp.cl;
int s, t, last, num;
string city1, city2;
cin >> city1; s = ID(city1);
cin >> city2; t = ID(city2);
cin >> last;
last = last / 100 * 60 + last % 100;
cin >> m;
int S = m<<1, T = m<<1|1;
dinic.init(T + 3);
for(int i = 0; i < m; ++i){
cin >> city1 >> city2 >> num >> fly[i].st >> fly[i].tt;
fly[i].s = ID(city1);
fly[i].t = ID(city2);
fly[i].st = fly[i].st / 100 * 60 + fly[i].st % 100;
fly[i].tt = fly[i].tt / 100 * 60 + fly[i].tt % 100;
if(fly[i].s == s) dinic.addEdge(S, i<<1, INF);
if(fly[i].t == t && fly[i].tt <= last) dinic.addEdge(i<<1|1, T, INF);
dinic.addEdge(i<<1, i<<1|1, num);
for(int j = 0; j < i; ++j){
if(fly[i].t == fly[j].s && fly[i].tt + 30 <= fly[j].st) dinic.addEdge(i<<1|1, j<<1, INF);
else if(fly[j].t == fly[i].s && fly[j].tt + 30 <= fly[i].st) dinic.addEdge(j<<1|1, i<<1, INF);
}
}
cout << dinic.maxflow(S, T) << endl;
}
return 0;
}

  

UVaLive 3645 Objective: Berlin (最大流)的更多相关文章

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

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

  2. UVALIVE 3645 Objective: Berlin

    最大流 .以航班为节点进行最大流. 容量限制进行拆点. 如果时间地点满足可以建一条边. 具体看代码.变量名被修改过了.一开始的变量名可能比较容易看懂 但CE了.可能与库里的变量重复了. AC代码 #i ...

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

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

  4. UVA - 1161 Objective: Berlin(最大流+时序模型)

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

  5. UVa1161 Objective: Berlin(最大流)

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

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

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

  7. UVALive 6887 Book Club 最大流解最大匹配

    题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  8. Uvalive 4865 Data Recovery 最大流

    题意就是 给一个50 * 50的矩阵 然后给出每行每列元素的和 和一个初始矩阵 矩阵中有些是未知,有些是已知 然后我们求目标矩阵就是把能确定的元素的值求出来,实在不能确定的就置为-1 所有矩阵元素的值 ...

  9. UVALive 4863 Balloons 贪心/费用流

    There will be several test cases in the input. Each test case will begin with a line with three inte ...

随机推荐

  1. CentOS Tomcat启动 Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

    链接:http://blog.csdn.net/shangdiyisi/article/details/9477521 [bravoinfo@bravoinfo-hk-01 apache-tomcat ...

  2. Mysql 触发器 A表记录到B表

    1:查询出需要的列名 备用 #列名 select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='yunpiaobox_ ...

  3. 在JSP页面中显示动态时间

    源地址:http://blog.csdn.net/aitcax/article/details/41285305 静态时间: 1.页面首部添加 <%@page import="java ...

  4. list接口如何使用

    1集合类,在java语言中的java.util包提供了一些集合类,这些集合类又被称作容器. 2区别集合类和数组.(1)数组的长度是固定的,集合的长度是可变的.(2)数组是用来存放基本数据类型的,集合是 ...

  5. PPT地图 - 动态显示省份扩散效果

    找一张中国地图矢量图,这个要找半天,自己画难度有点大.图中每个省份都是单独一张图.从我的百度云盘下载  提取码: 61ha 选中一个省份图块并复制,填充复制图块的颜色,拖拽该图块覆盖住该省份原来位置. ...

  6. 【Java】JVM(四)、虚拟机参数配置

    1. -Xms20M      JVM启动时候的内存大小为20M   2. -Xmx20M     JVM内存最大值是20M 将其与Xms大小一致可以避免JVM内存自动扩展   3. -Xss128K ...

  7. sysdig

    centos 7 安装 https://sysdig.com/opensource/sysdig/install/ 1) Trust the Draios GPG key, configure the ...

  8. Linux Shell中有三种引号的用法

    Linux Shell中有三种引号,分别为双引号(" ").单引号(' ')以及反引号(` `). 其中双引号对字符串中出现的$.''.`和\进行替换:单引号不进行替换,将字符串中 ...

  9. LPSN获取菌python脚本

    本文转载于https://mp.weixin.qq.com/s?__biz=MzIxNzEzODA5NQ==&mid=2649373408&idx=1&sn=232c2cb36 ...

  10. CentOS 6.3安装配置supervisor进程管理工具

    1. Supervisor是一个C/S系统,它可以在类unix操作系统让用户来监视和控制后台服务进程的数量,一个很重要的功能就是监控服务器的主要后台进程,并在出现问题是自动重启. 2. 根据服务器上的 ...