ACM->最大流的dinic递归算法
来源:互联网 发布:2018年 人工智能大会 编辑:程序博客网 时间:2024/04/29 01:55
1736. Chinese Hockey
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Sergey and Denis closely followed the Chinese Football Championship, which has just come to an end. They supported the Katraps and Komolotiv teams, but, unfortunately, these teams tied for last place in the championship. Sergey was so disappointed that he suggested Denis that they change to hockey fans.
There are n teams competing in the Chinese Ice Hockey Championship. During the season, each team must play with each other team exactly one game. If a team wins in the regulation time, it gets 3 points and the losing team gets 0 points. If the regulation time is ended in a draw, then the overtime is played. The team that wins in the overtime gets 2 points and the team that loses gets 1 point. A game can't end in a draw in ice hockey.
Denis wants to determine which team he will support. In order to make the choice, he has found a table on the Web in which it is shown for each team how many points it scored in the last year's season. Sergey suspects that there is a mistake in this table because no all-play-all tournament could end with such results. Is Sergey right?
Input
The first line contains the integer n (2 ≤ n ≤ 200). The second line contains n space-separated non-negative integers; they are the scores of the teams in the previous championship. The scores are given in the non-increasing order. The sum of all the scores is 3n(n–1)/2 . None of the teams scored more than 3(n–1) points.
Output
If Sergey is right and there is a mistake in the table, output “INCORRECT” in the only line. Otherwise, in the first line output “CORRECT” and in the following n(n–1)/2 lines output the results of the games. Each result must have the form “
i ? j
”, where i and j are the numbers of the teams that played the game and ?
can be <
, <=
, >=
, or >
, which means that the first team lost in the regulation time, lost in the overtime, won in the overtime, and won in the regulation time, respectively. The teams are numbered from 1 to n in the order in which they are given in the input.Samples
48 7 2 1
CORRECT2 <= 13 >= 41 > 34 < 21 > 42 > 3
48 8 1 1
INCORRECT
Problem Author: Alexander Ipatov (prepared by Igor Chevdar)
Problem Source: XIV Open USU Championship
Problem Source: XIV Open USU Championship
Tags: none
)EK算法过不去,普通dinic也过去不去
#include <iostream>#include <queue>#include <stack>#include <cmath>#include <algorithm>#include <string.h>using namespace std;const int MAXN = 200 + 10;const int INF = 0xfffffff;struct Edge{int v, w, next;}edge[MAXN * MAXN * 4];int e, head[MAXN * MAXN / 2];int cur[MAXN * MAXN / 2];int s, t, n;int temp[MAXN];int dis[MAXN * MAXN / 2];void add(int u, int v, int w){edge[e].v = v;edge[e].w = w;edge[e].next = head[u];head[u] = e++;edge[e].v = u;edge[e].w = 0;edge[e].next = head[v];head[v] = e++;}void init(){e = 0;memset(head, -1, sizeof(head));}int q[MAXN * MAXN / 2];bool bfs(){memset(dis, 0, sizeof(dis));dis[s] = 1;int heads, tail;heads = tail = 0;q[tail++] = s;while (heads != tail){int curs = q[heads++];for (int i = head[curs]; i != -1; i = edge[i].next){int v = edge[i].v;if (dis[v] == 0 && edge[i].w){dis[v] = dis[curs] + 1;q[tail++] = v;if (v == t){return true;}}}}return false;}int dfs(int u, int f){if (u == t || f == 0){return f;}int flow = 0;for (int i = head[u]; i != -1; i = edge[i].next){int v = edge[i].v;if (dis[v] == dis[u] + 1 && edge[i].w){int t = min(edge[i].w, f - flow);int inc = dfs(v, t);flow += inc;edge[i].w -= inc;edge[i ^ 1].w += inc;if (!(f - flow)){break;}}}if (!flow){dis[u] = -1;}return flow;}int dinic(){int Maxflow = 0;while (bfs()){Maxflow += dfs(s, INF);}return Maxflow;}void solve(){s = 0;t = n * (n - 1) / 2 + n + 1;int cnt = 1;for (int i = 1; i <= n; i++){for (int j = i + 1; j <= n; j++){add(cnt, i + n * (n - 1) / 2, 3);add(cnt, j + n * (n - 1) / 2, 3);cnt++;}}for (int i = 1; i <= n * (n - 1) / 2; i++){add(0, i, 3);}for (int i = 1; i <= n; i++){add(i + n * (n - 1) / 2, t, temp[i]);}cnt = 0;if (dinic() == n * (n - 1) / 2 * 3){printf("CORRECT\n");for (int i = 1; i <= n; i++){for (int j = i + 1; j <= n; j++){int ans = 3 - edge[cnt].w;cnt += 4;if (ans == 3){printf("%d > %d\n", i, j);}else if (ans == 2){printf("%d >= %d\n", i, j);}else if (ans == 1){printf("%d <= %d\n", i, j);}else{printf("%d < %d\n", i, j);}}}}else{printf("INCORRECT\n");}}void input(){while (scanf("%d", &n) != EOF){init();for (int i = 1; i <= n; i++){scanf("%d", &temp[i]);}solve();}}int main(){input();return 0;}
- ACM->最大流的dinic递归算法
- 最大流的Dinic算法
- HDU3549(最大流算法的Dinic算法)
- HDU ACM 3572 Task Schedule 网络最大流->dinic算法
- ACM 最大流 dinic 模板
- Dinic算法最大流。。
- 最大流dinic算法
- 最大流 dinic算法
- 最大流 dinic算法
- 最大流-dinic算法
- 最大流-Dinic算法
- 最大流 Dinic算法
- dinic算法求最大流的学习
- 最大流算法 -- Dinic算法
- dinic算法 最大流 PKU1459
- 最大流dinic算法分析
- dinic 算法求最大流
- Dinic算法求最大流
- ubuntu下sed编辑器的简单使用
- 关于map容器的insert成员的返回值说明
- 矩阵的妙用一例
- 我的Eclipse快捷键
- (n-1)s2/ó2是自由度为n-1的卡方分布
- ACM->最大流的dinic递归算法
- 计算闰年平年
- pat 1063
- 设计模式之-【Builder模式】
- C++之冒泡排序
- sql 2005 sql 2008 删除日志 清除日志
- 如何编译Support7Demos测试appcompat
- 最长队名
- C#中如何使用static静态变量