UVALive 2531 The K-League 最大流
来源:互联网 发布:栏目包装 知乎 编辑:程序博客网 时间:2024/04/29 17:39
题目:
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=532
题意:
有n支队伍在比赛,每支队伍要打的比赛数相同,每场比赛一定会分胜负,没有平局。现在给出每支队伍胜利的场数wi和失败的场数di,再给出每两个队伍之间还剩余的比赛的数量,求出所有可能获胜的队伍,获胜场数最多的即是冠军,允许并列
题意:
判断第i支队伍能否获胜,那么首先有i参加的比赛全都让i获胜,求出i胜利的场数sum。设有队伍j,k,然后把j,k之间的比赛看作一个点,从源点向此点连边,容量为a[j][k],从此点向队伍j,k连边,容量大于a[j][k]即可,这样的意思是有a[j][k]分,可以分配给j或者k,然后从每个队伍向汇点连边,容量为sum - wj,意思是只允许第j支队伍最多再胜利sum-wj场,否则的话,第j支队伍的胜利场数就大于第i支队伍了,建图完成,跑最大流判断是否满流,满流的意义是所有的比赛都确定了胜负,而且每支队伍的得分都不超过第i支队伍,即第i支队伍可以获胜,不满流说明了在不超过第i支队伍分数的情况下,有的比赛无法确定胜负,即确定胜负一定有队伍的分数超过第i支队伍。另外,注意sum-wj为负时,最大流满流并不能代表上述的意义,所以要特判,直接判i不能获胜
#include <bits/stdc++.h>using namespace std;const int N = 1010;const int INF = 0x3f3f3f3f;struct edge{ int to, cap, next;}g[N*100];int level[N], cur[N], que[N], pre[N], gap[N];int cnt, head[N];int ss, tt, nv;void add_edge(int v, int u, int cap){ g[cnt].to = u, g[cnt].cap = cap, g[cnt].next = head[v], head[v] = cnt++; g[cnt].to = v, g[cnt].cap = 0, g[cnt].next = head[u], head[u] = cnt++;}int sap(int s, int t){ memset(level, 0, sizeof level); memset(gap, 0, sizeof gap); memcpy(cur, head, sizeof head); gap[0] = nv; int v = pre[s] = s, flow = 0, aug = INF; while(level[s] < nv) { bool flag = false; for(int &i = cur[v]; i != -1; i = g[i].next) { int u = g[i].to; if(g[i].cap > 0 && level[v] == level[u] + 1) { flag = true; pre[u] = v; v = u; aug = min(aug, g[i].cap); if(v == t) { flow += aug; while(v != s) { v = pre[v]; g[cur[v]].cap -= aug; g[cur[v]^1].cap += aug; } aug = INF; } break; } } if(flag) continue; int minlevel = nv; for(int i = head[v]; i != -1; i = g[i].next) { int u = g[i].to; if(g[i].cap > 0 && level[u] < minlevel) minlevel = level[u], cur[v] = i; } if(--gap[level[v]] == 0) break; level[v] = minlevel + 1; gap[level[v]]++; v = pre[v]; } return flow;}int main(){ int t, n; int w[30], d[30], res[30], a[30][30]; scanf("%d", &t); while(t--) { scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d%d", &w[i], &d[i]); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) scanf("%d", &a[i][j]); int tot = 0; for(int i = 1; i <= n; i++) { int sum = w[i]; for(int j = 1; j <= n; j++) sum += a[i][j]; bool flag = true; for(int j = 1; j <= n; j++) if(sum < w[j])//特判 { flag = false; break; } if(!flag) continue; cnt = 0; memset(head, -1, sizeof head); ss = 0, tt = n*n + n + 1, nv = tt + 1; int tm = 0; for(int j = 1; j <= n; j++) { if(j == i) continue; for(int k = 1; k < j; k++) { if(k == i) continue; tm += a[j][k]; add_edge(ss, (j-1)*n + k, a[j][k]); add_edge((j-1)*n + k, n*n + j, INF); add_edge((j-1)*n + k, n*n + k, INF); } } for(int j = 1; j <= n; j++) { if(j == i) continue; add_edge(n*n + j, tt, sum - w[j]); } if(sap(ss, tt) == tm) res[tot++] = i; } for(int i = 0; i < tot; i++) printf("%d%c", res[i], i == tot-1 ? '\n' : ' '); } return 0;}
0 0
- UVALive 2531 The K-League 最大流
- UVALive - 2531 The K-League(最大流+枚举)
- LA 2531 The K-league 最大流
- UVALive 2531 The K-League(最大流、公平分配模型)
- UVALive 2531 The K-League 网络流+建图
- UVAlive2531 The K-League(最大流)
- [蓝书/Ch5] The K-League UVALive
- uva 1306 The K-League (最大流)
- UVA 1306 The K-League (最大流)
- LA 2531 The K-League
- UVA 1306 LA 2531 The K-League
- uva1306 - The K-League 网络流
- The K-League (网络流,建图难)
- Uva 1306 The K-League
- Uva-1306-The K-League
- UVA 1306 - The K-League(网络流)
- poj 1336 The K-League (网络流)
- POJ 1336 The K-League 笔记
- 系统的简单注解
- DOCKER 的安装和卸载
- 段错误
- day16-listener&filter
- 对sftp账号提供读写权限的控制
- UVALive 2531 The K-League 最大流
- SparkHBase java版本
- 线程对象的创建和获取线程的名称
- maven 打包java 程序没有主清单属性
- 一款很好用的Jquery 打印插件——jQuery.print.js
- day17-基础加强
- wireshark http2抓包
- Conn java版本
- 求知过程之json