【Uvalive 2531】 The K-League (最大流-类似公平分配问题)
【题意】
有n个队伍进行比赛,每场比赛,恰好有一支队伍取胜、一支队伍败。每个队伍需要打的比赛场数相同,给你每个队伍目前已经赢得场数和输得场数,再给你一个矩阵,第 i 行第 j 列 表示队伍 i 和队伍 j 还需要打的比赛数,问你哪些队伍有可能获得冠军(胜场最多的即为冠军,可以并列)。
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, . . . , wn, dn,
each at most 100, where wi and di are the current numbers of wins and defeats for team i, respectively;
the third line contains n
2 nonnegative integers a1,1, a1,2, . . . , a1,n, a2,1, a2,2, . . . , a2,n, · · · , an,1, an,2, . . . , an,n,
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 is equal to 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
【分析】
枚举判断每个队伍是否可以是冠军。
然后贪心的思想,想让他在接下来的比赛中全部获胜,接下来只用判断其他队伍的比赛是否可以相互制约,使得枚举的是总冠军。
st->(u,v),表示比赛,流量为比场数。
(u,v)->u (u,v)->v 流量为INF
u->ed 流量为tot-w[u] ,tot为枚举的那个的现在计算出的胜利场数,如果他是冠军,那么其他队伍的胜利场数不能超过他。
跑最大流,然后判断st->xxx 是否满流。
这题跟公平分配问题是相似的模型。
把每场比赛看成“任务”,每支队伍看成“处理器”,tot是制约(相当于我们二分的答案)。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define Maxn 30
#define Mn 1010
#define INF 0xfffffff struct node
{
int x,y,f,o,next;
}t[Mn*];
int len,first[Mn]; int mymin(int x,int y) {return x<y?x:y;} void ins(int x,int y,int f)
{
if(f<=) return;
t[++len].x=x;t[len].y=y;t[len].f=f;
t[len].next=first[x];first[x]=len;t[len].o=len+;
t[++len].x=y;t[len].y=x;t[len].f=;
t[len].next=first[y];first[y]=len;t[len].o=len-;
} int w[Maxn],d[Maxn],a[Maxn][Maxn];
int n; void init()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&w[i],&d[i]);
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
scanf("%d",&a[i][j]);
for(int i=;i<=n;i++)
{
a[i][]=;
for(int j=;j<=n;j++) a[i][]+=a[i][j];
}
} int dis[Mn],st,ed;
queue<int > q;
bool bfs()
{
while(!q.empty()) q.pop();
memset(dis,-,sizeof(dis));
q.push(st);dis[st]=;
while(!q.empty())
{
int x=q.front();
for(int i=first[x];i;i=t[i].next) if(t[i].f>)
{
int y=t[i].y;
if(dis[y]==-)
{
dis[y]=dis[x]+;
q.push(y);
}
}
q.pop();
}
if(dis[ed]==-) return ;
return ;
} int ffind(int x,int flow)
{
if(x==ed) return flow;
int now=;
for(int i=first[x];i;i=t[i].next) if(t[i].f>)
{
int y=t[i].y;
if(dis[y]==dis[x]+)
{
int a=ffind(y,mymin(flow-now,t[i].f));
t[i].f-=a;
t[t[i].o].f+=a;
now+=a;
}
if(now==flow) break;
}
if(now==) dis[x]=-;
return now;
} int max_flow()
{
int ans=;
while(bfs())
{
ans+=ffind(st,INF);
}
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
init();
bool op=;
for(int i=;i<=n;i++)
{
int tot=a[i][]+w[i],cnt,sum=;
len=;
memset(first,,sizeof(first));
st=n+,ed=st+,cnt=ed;
bool ok=;
for(int j=;j<=n;j++) if(j!=i)
{
ins(j,ed,tot-w[j]);
if(tot-w[j]<) ok=;
}
for(int j=;j<=n;j++) if(j!=i)
for(int k=j+;k<=n;k++) if(k!=i)
{
sum+=a[j][k];
ins(st,++cnt,a[j][k]),ins(cnt,j,INF),ins(cnt,k,INF);
}
int x=max_flow();
if(x!=sum) ok=;
if(ok)
{
if(op) printf(" ");
op=;
printf("%d",i);
}
}
// if(T)
printf("\n");
}
return ;
}
输出文件末不输出空行是WA,行末有空格是PE,也是。。
2016-11-04 07:47:58
【Uvalive 2531】 The K-League (最大流-类似公平分配问题)的更多相关文章
- uvalive 3231 Fair Share 公平分配问题 二分+最大流 右边最多流量的结点流量尽量少。
/** 题目: uvalive 3231 Fair Share 公平分配问题 链接:https://vjudge.net/problem/UVALive-3231 题意:有m个任务,n个处理器,每个任 ...
- 【 UVALive - 5095】Transportation(费用流)
Description There are N cities, and M directed roads connecting them. Now you want to transport K un ...
- UVaLive 2531 The K-League (网络流)
题意:有 n 个队伍进行比赛,每个队伍比赛数目是一样的,每场恰好一个胜一个负,给定每个队伍当前胜的场数败的数目,以及两个队伍剩下的比赛场数,问你冠军队伍可能是哪些队. 析:对每个队伍 i 进行判断是不 ...
- 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 ...
- K - Rochambeau - poj2912(类似食物链)
一群小孩玩一个简单石头布布游戏,这些小孩会分成三组(组内可能没有人)+一个自由人(比翻译成裁判合理多了),同一组的小孩只会出同一种手势(不会变的),不过裁判可以出任意的手势,这些小孩能就会相互猜拳玩, ...
- UVaLive 4597 Inspection (网络流,最小流)
题意:给出一张有向图,每次你可以从图中的任意一点出发,经过若干条边后停止,然后问你最少走几次可以将图中的每条边都走过至少一次,并且要输出方案,这个转化为网络流的话,就相当于 求一个最小流,并且存在下界 ...
- POJ1336 The K-League[最大流 公平分配问题]
The K-League Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 715 Accepted: 251 Descri ...
- floyd + 最大流 (奶牛分配问题)
FJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 &l ...
随机推荐
- (转)常用CSS优化总结——网络性能与语法性能建议
原文地址:http://www.cnblogs.com/dolphinX/p/3508657.html 在前端面试中最常见的问题就是页面优化和缓存(貌似也是页面优化),被问了几次后心虚的不行,平然平时 ...
- struts2学生信息管理系统篇章②进度报告篇章
之前做这个系统的时候是什么都不懂的! 经过一个月的时间,慢慢的java的知识都捡起来了. 对struts2和mvc模式都有一一定程度的了解,汇报一下上次的进度. 这个系统我所有的功能中我暂时只做到了下 ...
- andorid 平台调用Web Service , 图片传输
今天学习了下android调用web service,进行图片传输 下面是代码详解: onActivityResult 方法在图片剪裁完成之后调用: protected void onActivity ...
- C#类和成员定义
1 定义类 C#用关键字class来定义类.默认情况下,类声明为内部(internal)的,即只有当前项目中的代码才能访问它.与之相对应的,还可以用public关键字来修饰,这样该类还可以由其 ...
- C#面向对象的一些东西
最近在复习C#面向对象,也就是说常说的3大特性:封装.继承和多态.首先说一下封装,其实封装最大的目的也是为了实现代码的解耦和重用.代码也是安全的(对外它隐藏了具体的实现,就好比我们拿个遥控器就能操作电 ...
- 是么是 API 和 SDK
API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码 ...
- 《程序员的思维修炼》摘抄start:2014年9月27日19:27:07
程序员的思维修炼:摘抄:考虑到社会中各个相关团体的复杂交互影响和社会的持续变化,在我看来当前最重要的两项技能就是: ▪沟通能力: ▪学习和思考能力.软件行业正在逐步提高沟通能力.特别是敏捷方法(见注解 ...
- 08_使用TCP/IP Monitor监视SOAP协议
[SOAP定义] SOAP 简单对象访问协议,基于http传输xml数据,soap协议体是xml格式.SOAP 是一种网络通信协议SOAP 即Simple Object Access Pr ...
- Poj 3259 Wormholes(spfa判负环)
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42366 Accepted: 15560 传送门 Descr ...
- mysql导入导出.sql文件 备份还原数据库
从数据库导出数据库文件: 进入你的MySQL的安装目录的bin目录或者在C盘的根目录都行,我选的是在bin目录下,下面的例子出第一个外将以在C盘的根目录来讲解 我的mysql安装在了C盘,C: ...