题意:给定一些航班,每个航班有人数,和起始终止时间,每次转机要花半小时,问限制时间内最多能有多少人从起始城市到终点城市。

析:差不多是裸板网络流的最大流问题,把每个航班都拆成两个点,这两个点之间连接一条流量为这个航班的容量,然后再暴力去查看能不能连接,如果能,

那么就连接一条容量无限的边,然后在源点和汇点加一个无限的容量边。

#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 <unordered_map>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10005;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int hr[]= {-2, -2, -1, -1, 1, 1, 2, 2};
const int hc[]= {-1, 1, -2, 2, -2, 2, -1, 1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
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 int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
const int maxm = 1000005; struct Edge{
int v, f, next;
};
int src, sink;
int g[maxn];
int nume;
Edge e[maxm];
map<string, int> mp;
int cnt; int getid(const string &s){
return mp.count(s) ? mp[s] : mp[s] = cnt++;
} void add(int u, int v, int c){
e[++nume].v = v;
e[nume].f = c;
e[nume].next = g[u];
g[u] = nume;
e[++nume].v = u;
e[nume].f = 0;
e[nume].next = g[v];
g[v] = nume;
} queue<int> q;
bool vis[maxn + 10];
int d[maxn + 10]; void bfs(){
memset(d, 0, sizeof d);
while(!q.empty()) q.pop();
vis[src] = true;
q.push(src);
while(!q.empty()){
int u = q.front(); q.pop();
for(int i = g[u]; i; i = e[i].next)
if(e[i].f && !vis[e[i].v]){
q.push(e[i].v);
d[e[i].v] = d[u] + 1;
vis[e[i].v] = true;
}
}
} int dfs(int u, int del){
if(u == sink) return del;
int ans = 0;
for(int i = g[u]; i && del; i = e[i].next)
if(e[i].f && d[e[i].v] == d[u] + 1){
int dd = dfs(e[i].v, Min(e[i].f, del));
e[i].f -= dd;
e[i^1].f += dd;
del -= dd;
ans += dd;
}
return ans;
} int maxflow(){
int ans = 0;
while(true){
memset(vis, 0, sizeof vis);
bfs();
if(!vis[sink]) return ans;
ans += dfs(src, INF);
}
}
char s[105], t[105];
struct node{
int u, v, c, start, last;
};
node a[maxm]; int cal(char *s){
int ans = 0;
ans += ((s[0] - '0') * 10 + s[1] - '0') * 60;
ans += ((s[2] - '0') * 10 + s[3] - '0');
return ans;
} bool judge(const node &lhs, const node &rhs){
return lhs.v == rhs.u && lhs.last + 30 <= rhs.start;
} int main(){
while(scanf("%d", &n) == 1){
scanf("%s", s);
cnt = 0;
mp.clear();
int ss = getid(s);
scanf("%s", t);
int tt = getid(t);
memset(g, 0, sizeof g);
nume = 1;
int time;
scanf("%s", s);
time = cal(s);
scanf("%d", &m);
char start[10], last[10];
src = 0; sink = 2 * m + 1;
for(int i = 1; i <= m; ++i){
scanf("%s %s %d %s %s", s, t, &a[i].c, start, last);
a[i].u = getid(s);
a[i].v = getid(t);
a[i].start = cal(start);
a[i].last = cal(last);
}
for(int i = 1; i <= m; ++i){
if(a[i].u == ss) add(0, i, INF);
if(a[i].v == tt && a[i].last <= time) add(i+m, 2*m+1, INF);
add(i, i+m, a[i].c);
for(int j = 1; j <= m; ++j)
if(i != j && judge(a[i], a[j])) add(i+m, j, INF);
}
printf("%d\n", maxflow());
}
return 0;
}

最新文章

  1. ie6下js更新元素display:block后,仍然不显示的hack办法
  2. Linux下的虚拟Bridge实现
  3. 正则表达式(http://tieba.baidu.com/p/882391125)
  4. C++中类的前向声明的用法
  5. 了解linux内存管理机制(转)
  6. Linux多线程编程阅读链接
  7. [转] web.xml文件详解
  8. margin,padding之我见
  9. Flex时间操作
  10. ecstore使用paypal支付显示不支持此支付
  11. hibernate连接时指定编码方式 hibernate中文乱码问题
  12. CSS3属性text-overflow(省略符)实战开发详解
  13. dashboard项目心得:
  14. [原创]CentOS实现智能DNS
  15. linux环境下安装redis扩展
  16. ADO.NET复习总结(6)-断开式数据操作
  17. UiAutomator2.0 - 与AccessibilityService的关联
  18. JS获取键盘事件
  19. 手把手使用Docker搭建SpringBoot微服务镜像
  20. html 之 body topmargin、leftmargin、rightmargin、bottomnargin

热门文章

  1. excludepathpatterns 无效
  2. python学习之-- redis模块管道/订阅发布
  3. POJ 1328 Radar Installation【贪心 区间问题】
  4. Java连接MySQL报错:CommunicationsException: Communications link failure
  5. cppcon
  6. Visual studio 2017 中的Javascript智能提示与调试
  7. zmq.error.ZMQError: Address already in use
  8. day5-WordCount
  9. Java线程池的简单使用
  10. shutdown abort模式丢失redo,使用隐含參数启库