Description

Sergey and Denis closely followed the Chinese Football Championship, which has just come to an end. They supported the Katraps andKomolotiv 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.

题目大意:有n支队,每两队之间进行一场比赛,胜者得3分,败者0分。若为加时赛胜利者2分,败者1分。现在给所有队伍比完赛的得分,问有没有可能构造出这个得分,并输出得到这个得分的每一场比赛的结果。

思路:构建网络流。新开源点S汇点T,从源点到每一场比赛连一条容量为3的边,从每一场比赛到这场比赛的双方连一条边,容量为无穷大(大于等于3就行),从每一支队到汇点连一条边,容量为这个队伍的最终得分。若满流,则有解。每场比赛到比赛双方的边的流量,就是这场比赛某方的得分。

代码(31MS):

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std; const int MAXN = * ;
const int MAXE = MAXN * ;
const int INF = 0x3fff3fff; struct SAP {
int head[MAXN], pre[MAXN], dis[MAXN], cur[MAXN], gap[MAXN];
int next[MAXE], to[MAXE], cap[MAXE], flow[MAXE];
int n, ecnt, st, ed; void init() {
memset(head, , sizeof(head));
ecnt = ;
} void add_edge(int u, int v, int c) {
to[ecnt] = v; cap[ecnt] = c; flow[ecnt] = ; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; cap[ecnt] = ; flow[ecnt] = ; next[ecnt] = head[v]; head[v] = ecnt++;
} void bfs() {
memset(dis, 0x3f, sizeof(dis));
queue<int> que; que.push(ed);
dis[ed] = ;
while(!que.empty()) {
int u = que.front(); que.pop();
++gap[dis[u]];
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(cap[p ^ ] && dis[v] > n) {
dis[v] = dis[u] + ;
que.push(v);
}
}
}
} int Max_flow(int ss, int tt, int nn) {
st = ss, ed = tt, n = nn;
int ans = , minFlow = INF, u;
for(int i = ; i <= n; ++i) {
cur[i] = head[i];
gap[i] = ;
}
bfs();
u = pre[st] = st;
while(dis[st] < n) {
bool flag = false;
for(int &p = cur[u]; p; p = next[p]) {
int &v = to[p];
if(cap[p] > flow[p] && dis[u] == dis[v] + ) {
flag = true;
minFlow = min(minFlow, cap[p] - flow[p]);
pre[v] = u;
u = v;
if(u == ed) {
ans += minFlow;
while(u != st) {
u = pre[u];
flow[cur[u]] += minFlow;
flow[cur[u] ^ ] -= minFlow;
}
minFlow = INF;
}
break;
}
}
if(flag) continue;
int minDis = n - ;
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(cap[p] > flow[p] && dis[v] < minDis) {
minDis = dis[v];
cur[u] = p;
}
}
if(--gap[dis[u]] == ) break;
++gap[dis[u] = minDis + ];
u = pre[u];
}
return ans;
}
} G; int n, a[];
int game_id[][]; int main() {
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
G.init();
int ss = n + n * (n - ) / + , tt = ss + ;
int cnt = n + ;
for(int i = ; i <= n; ++i) {
G.add_edge(i, tt, a[i]);
for(int j = i + ; j <= n; ++j) {
game_id[i][j] = G.ecnt;
G.add_edge(cnt, i, );
G.add_edge(cnt, j, );
G.add_edge(ss, cnt, );
++cnt;
}
}
if(G.Max_flow(ss, tt, tt) != * n * (n - ) / ) puts("INCORRECT");
else {
puts("CORRECT");
for(int i = ; i <= n; ++i) {
for(int j = i + ; j <= n; ++j) {
switch(G.flow[game_id[i][j]]) {
case :printf("%d < %d\n", i, j);break;
case :printf("%d <= %d\n", i, j);break;
case :printf("%d >= %d\n", i, j);break;
case :printf("%d > %d\n", i, j);break;
}
}
}
}
}

URAL 1736 Chinese Hockey(网络最大流)的更多相关文章

  1. URAL - 1736 - Chinese Hockey

    题意:n支队伍打比赛,每2队只进行1场比赛,规定时间内胜得3分,败得0分,若是打到了加时赛,那么胜得2分,败得1分,给出n支队伍最后的总得分,问这个结果是否是可能的,是的话输出“CORRECT”及各场 ...

  2. URAL 1736 Chinese Hockey 网络流+建图

    题目链接:点击打开链接 题意: 给定n个队伍的得分情况,输出随意一个可行解. n个队伍随意2个队伍 a, b 间有且仅有一场比赛. 比赛结果分4种: 1.a +3, b +0 2.a +0, b +3 ...

  3. P3376 【模板】网络最大流

    P3376 [模板]网络最大流 题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点 ...

  4. HDU 3549 网络最大流再试

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 同样的网络最大流 T了好几次原因是用了cout,改成printf就A了 还有HDU oj的编译器也不支持以 ...

  5. 一般增广路方法求网络最大流(Ford-Fulkerson算法)

    /* Time:2015-6-18 接触网络流好几天了 写的第一个模版————Ford-Fulkerson算法 作用:求解网络最大流 注意:源点是0 汇点是1 如果题目输入的是1到n 请预处理减1 * ...

  6. 算法模板——Dinic网络最大流 2

    实现功能:同Dinic网络最大流 1 这个新的想法源于Dinic费用流算法... 在费用流算法里面,每次处理一条最短路,是通过spfa的过程中就记录下来,然后顺藤摸瓜处理一路 于是在这个里面我的最大流 ...

  7. 算法模板——Dinic网络最大流 1

    实现功能:同sap网络最大流 今天第一次学Dinic,感觉最大的特点就是——相当的白话,相当的容易懂,而且丝毫不影响复杂度,顶多也就是代码长个几行 主要原理就是每次用spfa以O(n)的时间复杂度预处 ...

  8. 图论算法-网络最大流【EK;Dinic】

    图论算法-网络最大流模板[EK;Dinic] EK模板 每次找出增广后残量网络中的最小残量增加流量 const int inf=1e9; int n,m,s,t; struct node{int v, ...

  9. 网络最大流算法—EK算法

    前言 EK算法是求网络最大流的最基础的算法,也是比较好理解的一种算法,利用它可以解决绝大多数最大流问题. 但是受到时间复杂度的限制,这种算法常常有TLE的风险 思想 还记得我们在介绍最大流的时候提到的 ...

随机推荐

  1. iOS之蓝牙开发—CoreBluetooth详解

    CoreBluetooth的API是基于BLE4.0的标准的.这个框架涵盖了BLE标准的所有细节.仅仅只有新的iOS设备和Mac是和BLE标准兼容.在CoreBluetooth框架中,有两个主要的角色 ...

  2. ABAP术语-Function Module

    Function Module 原文:http://www.cnblogs.com/qiangsheng/archive/2008/02/18/1071827.html General-purpose ...

  3. numpy的总结

    一:基础篇 1)数值 import numpy as np np.set_printoptions(linewidth=200,suppress=True) a = np.array([1,2,3,4 ...

  4. myEclipse 常用快捷键,工具等记录

    小的不才,从北大青鸟毕业,出来之后到第一家公司进行工作,当时认为自己很牛逼,很无敌,但是出来之后发现在学校里学的那些东西,在工作中,除了会写一点if...else之外,连循环都很少写. 然而有用的工具 ...

  5. github 常用

    1.创建KEY,这个文件生成完了后,要保存好公钥和私钥文件 ssh-keygen -t rsa -C "abc@mail.com" 2.github上添加ssh密钥 3.拷贝公钥信 ...

  6. ubuntu如何设置Python的版本

    Ubuntu默认已经安装了Python的版本了,不过是Python2的版本. 我们安装好Python3想把他切换为系统默认的版本. sudo update-alternatives --config ...

  7. python3 练习题100例 (二十七)列表元素改写

    题目内容: 输入一个列表alist,要求列表中的每个元素都为正整数且不超过10: 将列表中的奇数变为它的平方,偶数除以2后打印新的列表(新的列表中所有元素仍都为整数). 可以使用以下实现列表alist ...

  8. 文件 I/O字符流

    import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOExceptio ...

  9. 最短路径算法 4.SPFA算法(1)

    今天所说的就是常用的解决最短路径问题最后一个算法,这个算法同样是求连通图中单源点到其他结点的最短路径,功能和Bellman-Ford算法大致相同,可以求有负权的边的图,但不能出现负回路.但是SPFA算 ...

  10. 43-Identity MVC:UI

    1-打开之前写的MvcCookieAuthSample项目, 在AccountController新加Register,Login方法 public class AccountController : ...