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

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1736

——>>赛后师弟说这是一道网络流大水题,果如其言~

设一个超级源点s,一个超级汇点t,各支队伍各为1个结点,各场比赛也各为1个结点,从s到各场比赛各连1条边,容量为3,从各场比赛到这场比赛的2支参赛队伍各连1条边,容量为3,最后从各支队伍向t各连1条边,容量为输入的对应得分。然后,跑一次最大流,若最大流为满流3 * n * (n-1) / 2,则得分是正确的,再根据各场比赛的流量输出相应的数据,否则得分是不正确的。

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue> using namespace std; const int maxv = 200 + 10;
const int maxn = 40000 + 10;
const int INF = 0x3f3f3f3f; int a[maxv], vs[maxv][maxv]; struct Edge{
int u;
int v;
int cap;
int flow;
}; struct Dinic{
int n, m, s, t;
vector<Edge> edges;
vector<int> G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn]; int addEdge(int uu, int vv, int cap){
edges.push_back((Edge){uu, vv, cap, 0});
edges.push_back((Edge){vv, uu, 0, 0});
m = edges.size();
G[uu].push_back(m-2);
G[vv].push_back(m-1);
return m-2;
} bool bfs(){
memset(vis, 0, sizeof(vis));
queue<int> qu;
qu.push(s);
d[s] = 0;
vis[s] = 1;
while(!qu.empty()){
int x = qu.front(); qu.pop();
int si = G[x].size();
for(int i = 0; i < si; i++){
Edge& e = edges[G[x][i]];
if(!vis[e.v] && e.cap > e.flow){
vis[e.v] = 1;
d[e.v] = d[x] + 1;
qu.push(e.v);
}
}
}
return vis[t];
} int dfs(int x, int a){
if(x == t || a == 0) return a;
int flow = 0, f;
int si = G[x].size();
for(int& i = cur[x]; i < si; i++){
Edge& e = edges[G[x][i]];
if(d[x] + 1 == d[e.v] && (f = dfs(e.v, min(a, e.cap-e.flow))) > 0){
e.flow += f;
edges[G[x][i]^1].flow -= f;
flow += f;
a -= f;
if(a == 0) break;
}
}
return flow;
} int Maxflow(int s, int t){
this->s = s;
this->t = t;
int flow = 0;
while(bfs()){
memset(cur, 0, sizeof(cur));
flow += dfs(s, INF);
}
return flow;
}
}; int main()
{
int n;
while(scanf("%d", &n) == 1){
Dinic din;
int t = n + n * (n-1) / 2 + 1;
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
din.addEdge(i, t, a[i]);
}
for(int i = 1, k = n+1; i <= n; i++)
for(int j = i+1; j <= n; j++, k++){
vs[i][j] = din.addEdge(0, k, 3);
din.addEdge(k, i, 3);
din.addEdge(k, j, 3);
}
if(din.Maxflow(0, t) == 3 * n * (n-1) / 2){
puts("CORRECT");
for(int i = 1; i <= n; i++)
for(int j = i+1; j <= n; j++){
int L = din.edges[vs[i][j]+2].flow;
int R = din.edges[vs[i][j]+4].flow;
if(L == 3 && R == 0) printf("%d > %d\n", i, j);
else if(L == 0 && R == 3) printf("%d < %d\n", i, j);
else if(L == 2 && R == 1) printf("%d >= %d\n", i, j);
else printf("%d <= %d\n", i, j);
}
}
else puts("INCORRECT");
}
return 0;
}

URAL - 1736 - Chinese Hockey的更多相关文章

  1. URAL 1736 Chinese Hockey(网络最大流)

    Description Sergey and Denis closely followed the Chinese Football Championship, which has just come ...

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

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

  3. 使用MySQL数据库将汉字转换成拼音的一个C语言小程序

    环境: mysql:mysql-5.1.65 centos:centos 6.5 编译命令: gcc -o chinesetopinyin chinesetopinyin.c -L/usr/lib/m ...

  4. URAL 1962 In Chinese Restaurant 数学

    In Chinese Restaurant 题目连接: http://acm.hust.edu.cn/vjudge/contest/123332#problem/B Description When ...

  5. URAL 1873. GOV Chronicles

    唔 神题一道 大家感受一下 1873. GOV Chronicles Time limit: 0.5 secondMemory limit: 64 MB A chilly autumn night. ...

  6. CTRL-Space always toggles Chinese IME (Windows 7、10)

    一.window占用了ctrl+空格的快捷键,影响开发工具的只能提示的使用. 二.解决方式: Go to Start > Type in regedit and start it (打开运行输入 ...

  7. OpenCascade Chinese Text Rendering

    OpenCascade Chinese Text Rendering eryar@163.com Abstract. OpenCascade uses advanced text rendering ...

  8. NetSuite Chinese Finance Reports

    NetSuite has a strong report customization application. The standard finance reports has a different ...

  9. Chinese economic influence in North Korea

    Where this new investment is being targeted is also interesting雄性禿 . "If you look at the econom ...

随机推荐

  1. UVA 10765 Doves and bombs

    给定一个无向的连通图,要求每个点去掉后连通分量的数目,然后输出连通分量最多的m个点. 分析: 先求出双连通分量,然后统计所有双连通分量中割顶出现的次数,最后求出的就是割顶去掉后剩下的双连通的数目,对于 ...

  2. GridView使用CommandField删除列实现删除时提示确认框

    在.net2005提供的GridView中我们可以直接添加一个CommandField删除列完后在它的RowDeleting事件中完成删除 GridView在使用CommandField删除时弹出提示 ...

  3. easyui源码翻译1.32--Dialog(对话框窗口)

    前言 扩展自$.fn.window.defaults.使用$.fn.dialog.defaults重写默认值对象.下载该插件翻译源码 该对话框是一种特殊类型的窗口,它在顶部有一个工具栏,在底部有一个按 ...

  4. QT做界面真是绝美,并且还可嵌入HTML与JS做界面(许多案例)

    1. 这年头想要酷炫, 还是用web最方便, QT自带嵌入式webkit, 然后用d3.js D3.js - Data-Driven Documents什么的, 各种酷炫的互动表随手而来.这里有各种各 ...

  5. free 命令解释

    free 命令 buffers and cached 解释 N多人总是询问,当在linux在输入free时内存总数怎么加起来不一样啊,下面我来解释一下free命令的输出. 我们运行free命令时都会看 ...

  6. netsh命令

    C:\Windows\System32>netsh interface ipv6 show address level=verbose 地址 ::1 参数-------------------- ...

  7. 搭建Git本地服务器

    搭建Git本地服务器 参考文章:http://www.ossxp.com/doc/git/gitolite.html 当前任务,学习中... 公司小范围用法: 服务器上做的: .在服务器上建立一个用户 ...

  8. Hadoop源代码分析【IO专题】

    由于Hadoop的MapReduce和HDFS都有通信的需求,需要对通信的对象进行序列化.Hadoop并没有采用Java的序列化(因为Java序列化比较复杂,且不能深度控制),而是引入了它自己的系统. ...

  9. 处理MVC中默认的Json方法返回时间的问题

    利用 Json方法返回 数据时,如果有时间格式,会变成 "\/Date(1369419656217)\/" 这个样子,问了同事找到个解决方法 using Newtonsoft.Js ...

  10. Linux上构建一个RADIUS服务器详解

    作为一名网络管理员,您需要为您所需管理的每个网络设备存放用于管理的用户信息.但是网络设备通常只支持有限的用户管理功能.学习如何使用Linux上的一个外部RADIUS服务器来验证用户,具体来说是通过一个 ...