POJ1336 The K-League[最大流 公平分配问题]
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 715 | Accepted: 251 |
Description
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
Output
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
公平分配模型
//
// 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[最大流 公平分配问题]的更多相关文章
- 【Uvalive 2531】 The K-League (最大流-类似公平分配问题)
[题意] 有n个队伍进行比赛,每场比赛,恰好有一支队伍取胜.一支队伍败.每个队伍需要打的比赛场数相同,给你每个队伍目前已经赢得场数和输得场数,再给你一个矩阵,第 i 行第 j 列 表示队伍 i 和队伍 ...
- uvalive 3231 Fair Share 公平分配问题 二分+最大流 右边最多流量的结点流量尽量少。
/** 题目: uvalive 3231 Fair Share 公平分配问题 链接:https://vjudge.net/problem/UVALive-3231 题意:有m个任务,n个处理器,每个任 ...
- POJ - 2516 Minimum Cost 每次要跑K次费用流
传送门:poj.org/problem?id=2516 题意: 有m个仓库,n个买家,k个商品,每个仓库运送不同商品到不同买家的路费是不同的.问为了满足不同买家的订单的最小的花费. 思路: 设立一个源 ...
- poj-2516.minimum cost(k次费用流)
Minimum Cost Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 19883 Accepted: 7055 Des ...
- hdu4106 区间k覆盖问题(连续m个数,最多选k个数) 最小费用最大流 建图巧妙
/** 题目:hdu4106 区间k覆盖问题(连续m个数,最多选k个数) 最小费用最大流 建图巧妙 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4106 ...
- POJ2699:The Maximum Number of Strong Kings(枚举+贪心+最大流)
The Maximum Number of Strong Kings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2488 ...
- UVALive-2531 The K-League (最大流建模+枚举)
题目大意:有n支足球队,已知每支球队的已胜场数和任意两支球队之间还需要的比赛场数a[i][j],求最终可能夺冠的所有球队. 题目分析:枚举所有的球队,对于球队 i 让它在接下来的比赛中全部获胜,如果这 ...
- 【wikioi】1034 家园(最大流+特殊的技巧)
http://wikioi.com/problem/1034/ 太神了这题. 其实一开始我以为是费用流,但是总感觉不对. 原因是我没看到一句话,特定的时刻到达特定的点!! 也就是说,并不是每艘船每次都 ...
- BZOJ 2324 营救皮卡丘(最小费用最大流)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2324 题意:n+1个城市(0到n).初始时K个 人都在0城市.城市之间有距离.要求(1) ...
随机推荐
- eclipse 突然 一直在loading descriptor for XXX (XXX为工程名)
问题: eclipse 启动后,啥也不干,就一直在loading descriptor for XXX (XXX为工程名),,其他什么操作都不能操作. 如下图所示,保存文件也无法保存. 这个怎么办? ...
- MySQL中索引和优化的用法总结
1.什么是数据库中的索引?索引有什么作用? 引入索引的目的是为了加快查询速度.如果数据量很大,大的查询要从硬盘加载数据到内存当中. 2.InnoDB中的索引原理是怎么样的? InnoDB是Mysql的 ...
- java servlet 几种页面跳转的方法及传值
java servlet 几种页面跳转的方法及传值 java web 页面之间传值有一下这几种方式1.form 表单传递参数2.url地址栏传递参数3.session4.cookie5.appli ...
- Lind.DDD.API核心技术分享
回到目录 关于Lind.DDD框架里API框架的技术点说明 讲解:张占岭 花名:仓储大叔 主要框架:Lind.DDD 目录 关于Lind.DDD.Authorization 关于授权的原理 关于Api ...
- PHP中的特殊类,接口类和抽象类(都不能直接实例化)
接口类不用实例化,需要一一实现接口定义的所有方法.关键字interface implements 接口interface 是一个规定,给人继承用的东西,有点像抽象类在里面定义的方法,却不去实例化,而需 ...
- java多线程-读写锁
Java5 在 java.util.concurrent 包中已经包含了读写锁.尽管如此,我们还是应该了解其实现背后的原理. 读/写锁的 Java 实现(Read / Write Lock Java ...
- jQuery实现选项联动轮播
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- PHP
* PHP语言1.基本内容 * PHP语言 - 类似于javascript语言的 * javascript是客户端(HTML)的脚本语言 * PHP是服务器端的脚本语言 * PHP文件的扩展名为&qu ...
- js--找字符串中出现最多的字符
在一个字符串中,如 'zhaochucichuzuiduodezifu',我们要找出出现最多的字符.本文章将详细说明方法思路. 先介绍两个string对象中的两个方法:indexOf()和charAt ...
- jqueryAPI使用之选择器
好一段时间没有更新博文了.刚学习完JS基础知识后,也进入到了JQ的学习.为了能熟练掌握JQ的使用,最好的方法就是反复多练,讲JQ中的API的每个知识点都练习一遍.如果能做到这个,那么对JQ就没那么陌生 ...