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. boost::asio::ip::tcp中几个重要类型

    typedef basic_stream_socket socket; 流式套接字,提供同/异步发送接收数据,连接,绑定,设置套接字选项等功能 对于socket中的connect()方法,它只针对某一 ...

  2. JQuery实现聊天对话框

    效果图如下: HTML代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  3. Maven里面多环境下的属性过滤(配置)

    情景:通常一个项目都为分为开发环境(dev)和测试环境(test)还有正式环境(prod),如果每次一打包都要手动地去更改配置文件,例如数据库连接配置.将会很容易出差错. 解决方案:maven pro ...

  4. CentOS7版本基础使用

    第1章 CentOS7的使用 1.1 为什么要使用CentOS7版本 CentOS7是在CentOS6基础上发布的新版本,与之前的版本相比,主要的更新包括: 1.内核更新到3.10.0 2.支持Lin ...

  5. lvs初体验

    一.简介 LVS是 Linux Virtual Server 的简称,也就是Linux虚拟服务器.这是一个由章文嵩博士发起的一个开源项目,它的官方网址是http://www.linuxvirtuals ...

  6. vuex重置所有state(可定制)

    在正式场景中我们经常遇到一个问题,就是登出页面或其他操作的时候,我们需要重置所有的vuex,让其变为初始状态,那么,就涉及到了多种方法:1.页面刷新: window.location.reload() ...

  7. java程序执行命令行,解锁数据库表

    有些表锁的时间长或其他原因,在plsql中不能解锁,只能用命令行解锁. 有些功能跨平台系统的交互偶尔会锁表,就需要自动解锁. 下面是解锁的代码: package com.lg.BreakOracleU ...

  8. python中字典的遍历

    用ipython运行情况如下: #新建字典 In [1]: name_cards = {'name':'sunwukong','QQ':'123124','addr':'秦皇岛'} #生成key对象 ...

  9. ruby Time类与Date类

    Time类用于表示时间.时间除了表示年月日时分秒的信息外,还包含了表示地域时差的时区(time zone)信息.例如我们可以计算中国当前时间是国际协调时间的几点 Date类只用于表示年月日.因此,相对 ...

  10. Leecode刷题之旅-C语言/python-100相同的树

    /* * @lc app=leetcode.cn id=100 lang=c * * [100] 相同的树 * * https://leetcode-cn.com/problems/same-tree ...