The K-League
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 715   Accepted: 251

Description

Supporters for the professional soccer clubs participating in the K-League, formerly the Korea Professional Soccer League, hold orderly and organized cheering, as did the Red Devils, the official supporters for the Korean national soccer team during the 2002 Korea-Japan World Cup. After many games of this season have been played, the supporters may wonder whether the team S they are backing can still win the championship. In other words, can winners be assigned for the remaining games so that no team ends with more victories than S?(Two or more teams can win the championship jointly.)

You are given the current number of wins and defeats, wi and di, for every team i, 1<=i<=n, and the remaining number, ai,j, of games to be played between every pair of teams i and j, 1<=i,j<=n, where n is the number of teams. The teams are numbered 1,2,...,n. You are to find all teams that have a possibility of winning the championship. Every team has to play the same number games during the season. For simplicity, we assume that there are no draws, that is, every game has a winner and a loser.

Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of three lines: the first line has an integer n, 1<=n<=25, that represents the number of teams in the test case; the second line contains 2n nonnegative integers w1,d1,w2,d2... each at most 100, where wi and di are the current numbers of wins and defeats for team i, respectively; the third line contains n2 nonnegative integers a1,1,a1,2,... each at most 10, where ai,j is the remaining number of games to be played between teams i and j . For all i and j, ai,j=aj,i. If i=j, then ai,j=0. The integers given in a line are delimited by one or more spaces. 

Output

Print exactly one line for each test case. The line should contain all teams that have a possibility of winning the championship, in an increasing order of team numbers. 

Sample Input

3
3
2 0 1 1 0 2
0 2 2
2 0 2
2 2 0
3
4 0 2 2 0 4
0 1 1
1 0 1
1 1 0
4
0 3 3 1 1 3 3 0
0 0 0 2
0 0 1 0
0 1 0 0
2 0 0 0

Sample Output

1 2 3
1 2
2 4

Source


公平分配模型
判断队伍i能否获胜,让i的所有比赛都获胜,其他就是把比赛的胜利分配给队伍,是他们的获胜次数<=i的获胜次数
每场比赛(i,j)一个点,s到(i,j)连容量为c[i][j]的边,(i,j)到i和j分别连INF
除i外节点j到t连 i获胜次数-win[j] 的边
注意 i获胜次数-win[j] 的边<0一定不行
//
// main.cpp
// poj1336
//
// Created by Candy on 26/11/2016.
// Copyright © 2016 Candy. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,INF=1e9;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int T,n,num,sum,win[N],los[N],s,t,c[N][N];
struct edge{
int v,ne,c,f;
}e[N<<];
int cnt,h[N];
inline void ins(int u,int v,int c){//printf("ins %d %d %d\n",u,v,c);
cnt++;
e[cnt].v=v;e[cnt].c=c;e[cnt].f=;e[cnt].ne=h[u];h[u]=cnt;
cnt++;
e[cnt].v=u;e[cnt].c=;e[cnt].f=;e[cnt].ne=h[v];h[v]=cnt;
}
int tot;
bool build(int x){//printf("build %d\n",tot);
cnt=;
memset(h,,sizeof(h));
for(int i=;i<=n;i++) if(i!=x){
for(int j=i+;j<=n;j++) if(j!=x){
int id=(i-)*n+j;
ins(s,id,c[i][j]);
ins(id,num+i,INF);
ins(id,num+j,INF);
}
ins(num+i,t,tot-win[i]);
if(tot-win[i]<) return false;
}
return true;
}
int cur[N];
int vis[N],d[N],q[N],head,tail;
bool bfs(){
memset(vis,,sizeof(vis));
memset(d,,sizeof(d));
head=tail=;
q[tail++]=s;d[s]=;vis[s]=;
while(head!=tail){
int u=q[head++];
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v;
if(!vis[v]&&e[i].c>e[i].f){
vis[v]=;d[v]=d[u]+;
q[tail++]=v;
if(v==t) return ;
}
}
}
return ;
}
int dfs(int u,int a){
if(u==t||a==) return a;
int flow=,f;
for(int &i=cur[u];i;i=e[i].ne){
int v=e[i].v;
if(d[v]==d[u]+&&(f=dfs(v,min(a,e[i].c-e[i].f)))>){
flow+=f;
e[i].f+=f;
e[((i-)^)+].f-=f;
a-=f;
if(a==) break;
}
}
return flow;
}
int dinic(){
int flow=;
while(bfs()){
for(int i=s;i<=t;i++) cur[i]=h[i];
flow+=dfs(s,INF);
}
return flow;
}
int main(int argc, const char * argv[]) {
T=read();
while(T--){
n=read();s=;t=n*n+n+;num=n*n;sum=;
for(int i=;i<=n;i++) win[i]=read(),los[i]=read();
for(int i=;i<=n;i++)
for(int j=;j<=n;j++) c[i][j]=read(),sum+=j>i?c[i][j]:; for(int i=;i<=n;i++){//printf("sol %d\n",i);
tot=win[i];
for(int j=;j<=n;j++) tot+=c[i][j];
if(!build(i)) continue;
int tmp=dinic();//printf("dinic %d sum %d %d\n",tmp,sum,sum-tot+win[i]);
if(tmp==sum-tot+win[i]) printf("%d ",i);
}
puts("");
} return ;
}
 
 
 

POJ1336 The K-League[最大流 公平分配问题]的更多相关文章

  1. 【Uvalive 2531】 The K-League (最大流-类似公平分配问题)

    [题意] 有n个队伍进行比赛,每场比赛,恰好有一支队伍取胜.一支队伍败.每个队伍需要打的比赛场数相同,给你每个队伍目前已经赢得场数和输得场数,再给你一个矩阵,第 i 行第 j 列 表示队伍 i 和队伍 ...

  2. uvalive 3231 Fair Share 公平分配问题 二分+最大流 右边最多流量的结点流量尽量少。

    /** 题目: uvalive 3231 Fair Share 公平分配问题 链接:https://vjudge.net/problem/UVALive-3231 题意:有m个任务,n个处理器,每个任 ...

  3. POJ - 2516 Minimum Cost 每次要跑K次费用流

    传送门:poj.org/problem?id=2516 题意: 有m个仓库,n个买家,k个商品,每个仓库运送不同商品到不同买家的路费是不同的.问为了满足不同买家的订单的最小的花费. 思路: 设立一个源 ...

  4. poj-2516.minimum cost(k次费用流)

    Minimum Cost Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19883   Accepted: 7055 Des ...

  5. hdu4106 区间k覆盖问题(连续m个数,最多选k个数) 最小费用最大流 建图巧妙

    /** 题目:hdu4106 区间k覆盖问题(连续m个数,最多选k个数) 最小费用最大流 建图巧妙 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4106 ...

  6. POJ2699:The Maximum Number of Strong Kings(枚举+贪心+最大流)

    The Maximum Number of Strong Kings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2488 ...

  7. UVALive-2531 The K-League (最大流建模+枚举)

    题目大意:有n支足球队,已知每支球队的已胜场数和任意两支球队之间还需要的比赛场数a[i][j],求最终可能夺冠的所有球队. 题目分析:枚举所有的球队,对于球队 i 让它在接下来的比赛中全部获胜,如果这 ...

  8. 【wikioi】1034 家园(最大流+特殊的技巧)

    http://wikioi.com/problem/1034/ 太神了这题. 其实一开始我以为是费用流,但是总感觉不对. 原因是我没看到一句话,特定的时刻到达特定的点!! 也就是说,并不是每艘船每次都 ...

  9. BZOJ 2324 营救皮卡丘(最小费用最大流)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2324 题意:n+1个城市(0到n).初始时K个 人都在0城市.城市之间有距离.要求(1) ...

随机推荐

  1. 前端 angular 和 bootstrap 的安装步骤

    1.安装bower模块: npm install -g bower --registry=http://registry.npm.taobao.org 2.创建.bowerrc 文件存放 前端相关的模 ...

  2. java多线程-信号量

    Semaphore(信号量)是一个线程同步结构,用于在线程间传递信号,以避免出现信号丢失,或者像锁一样用于保护一个关键区域.自从 5.0 开始,jdk 在 java.util.concurrent 包 ...

  3. Javascript实现格式化输出

    前两天看面试题,其中有一道要实现js的格式化输出,具体给出的是: Javascript实现格式化输出,比如输入999999999,输出为999,999,999 我的实现方式是 function for ...

  4. AMD and CMD are dead之JS工程化终极解决方案KMD.js版本0.0.1发布

    回顾 经过两天晚上疯狂的开发调试,伴随着大量掉落的头发和酸痛的颈椎,KMD.js赢来了第一个稳定版本.在此期间KMD规范也有所修改和完善. 这两天主要完成的功能有: 按需加载 版本控制 模块管理 便捷 ...

  5. MYSQL进阶,新手变司机

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用. SELECT * FROM ( S ...

  6. Android Studio调试方法学习笔记

    (注:本人所用Android Studio的Keymap已设为Eclipse copy) 1.设置断点 只有设置断点,才好定位要调试什么地方,否则找不到要调试的地方,无法调试.(调试过程中也可以增加断 ...

  7. android handler传递消息机制

    当工作线程给主线程发送消息时,因为主线程是有looper的,所以不需要初始化looper,注意给谁发消息就关联谁的handler,此时用的就是主线程的handler handler会把消息发送到Mes ...

  8. MySQL5.7 修改密码

    MySQL5.7 修改密码 mysql> update mysql.user set authentication_string = password('新密码') where user='用户 ...

  9. jquery 获取多个select name 的值

    html {foreach from=$month_arr item=dateArr key=i}<tr> <td>{$dateArr.m}</td> <td ...

  10. 通过jconsole监控tomcat JVM 内存、线程、CPU

    从Java 5开始 引入了 JConsole,来监控 Java 应用程序性能和跟踪 Java 中的代码.jconsole是JDK自带监控工具,只需要找到 JDK 安装路径,打开 bin 文件夹,双击  ...