题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33451

【思路】

最大流。

大体思路是枚举每个队伍,最大流判断是否可能成为冠军。

构图:

1 建立ST,比赛(u,v)建立n^2个结点,队伍u建立n个结点。

2 由S向(u,v)连容量为a[u][v]的边,由(u,v)向u和v连容量为INF的边,由u向T连容量为total-w[u]的边。

3 如果从S发出的边都满载则该team可行。

【代码】

 #include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#define FOR(a,b,c) for(int a=(b);a<(c);a++)
using namespace std; const int maxn = +;
const int INF = 1e9; struct Edge{
int u,v,cap,flow;
};
struct Dinic {
int n,m,s,t;
bool vis[maxn];
int d[maxn],cur[maxn];
vector<int> G[maxn];
vector<Edge> es; void init(int n) {
this->n=n;
es.clear();
for(int i=;i<n;i++) G[i].clear();
}
void AddEdge(int u,int v,int cap) {
es.push_back((Edge){u,v,cap,});
es.push_back((Edge){v,u,,});
m=es.size();
G[u].push_back(m-);
G[v].push_back(m-);
} bool BFS() {
queue<int> q;
memset(vis,,sizeof(vis));
q.push(s); vis[s]=; d[s]=;
while(!q.empty()) {
int u=q.front(); q.pop();
for(int i=;i<G[u].size();i++) {
Edge& e=es[G[u][i]];
int v=e.v;
if(!vis[v] && e.cap>e.flow) {
vis[v]=;
d[v]=d[u]+;
q.push(v);
}
}
}
return vis[t];
}
int DFS(int u,int a) {
if(u==t || a==) return a;
int flow=,f;
for(int& i=cur[u];i<G[u].size();i++){
Edge& e=es[G[u][i]];
int v=e.v;
if( d[v]==d[u]+ && (f=DFS(v,min(a,e.cap-e.flow)))> ) {
e.flow+=f;
es[G[u][i]^].flow-=f;
flow+=f,a-=f;
if(!a) break;
}
}
return flow;
}
int Maxflow(int s,int t) {
this->s=s , this->t=t;
int flow=;
while(BFS()) {
memset(cur,,sizeof(cur));
flow+=DFS(s,INF);
}
return flow;
}
} dc; int n;
int w[maxn],d[maxn],a[maxn][maxn]; int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d%d",&w[i],&d[i]);
int sum=;
for(int i=;i<n;i++)
for(int j=;j<n;j++) scanf("%d",&a[i][j]) , sum+=a[i][j];
sum/=;
int S=n*n+n , T=S+;
bool first=;
for(int team=;team<n;team++)
{
int total=w[team];
for(int i=;i<n;i++) total+=a[team][i];
bool flag=;
for(int i=;i<n;i++) if(w[i]>total) flag=; //即使全胜依然不可能是冠军
if(flag) continue;
dc.init(n*n+n+);
for(int i=;i<n;i++) {
for(int j=i+;j<n;j++) {
int r=i*n+j;
if(a[i][j]) dc.AddEdge(S,r,a[i][j]);
dc.AddEdge(r,n*n+i,INF) , dc.AddEdge(r,n*n+j,INF);
}
dc.AddEdge(n*n+i,T,total-w[i]);
}
if(dc.Maxflow(S,T)==sum) {
if(first) first=; else putchar(' ');
printf("%d",team+);
}
}
putchar('\n');
}
return ;
}

UVAlive2531 The K-League(最大流)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. hdu3081 Marriage Match II(二分+并查集+最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意: n个女生与n个男生配对,每个女生只能配对某些男生,有些女生相互是朋友,每个女生也可以跟她 ...

  8. POJ 2516 Minimum Cost (费用流)

    题面 Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area ...

  9. 【费用流】【CODEVS】1227 方格取数2

    [算法]最小费用最大流(费用流) [题解] 费用流:http://www.cnblogs.com/onioncyc/p/6496532.html 本题构图: 在有限的k次行走中尽可能多的拿到数字,明显 ...

随机推荐

  1. U3D Trigger事件触发

    使用Trigger事件触发,可以达到虽然触发了,可是不改变任何效果. 这个是进入时候触发的: void OnTriggerEnter2D(Collider2D other) { print (othe ...

  2. underscorejs-countBy学习

    2.20 countBy 2.20.1 语法 _.countBy(list, iteratee, [context]) 2.20.2 说明 排序一个列表组成一个组,并且返回各组中的对象的数量的计数.类 ...

  3. .net程序员必须知道的知识

    A while back, I posted a list of ASP.NET Interview Questions. Conventional wisdom was split, with ab ...

  4. win7访问windows server 2003服务器出现未知的用户名或者错误的密码(转载)

    直接放答案,感谢网友提供答案,否则自已还一直在纳闷,为什么? win7系统的安全机制限制了登陆.只要系统时间和win2003服务器的系统时间相差很多,系统就会阻止其登陆,并显示错误信息:"未 ...

  5. Linux下定时备份数据库

    linux下使用crontab定时备份MYSQL数据库的方法只需按照下面3步做,一切都在你的掌控之下: 第一步:在服务器上配置备份目录代码: mkdir /var/lib/mysqlbackup cd ...

  6. Android输入法开发

    1. 概念 * IMF: 输入法框架(Input Method Framework) * IM: 输入法(Input Method) * IMS: 输入法服务(Input Method Service ...

  7. Lua 5.1 for Delphi 2010

    This is a Lua 5.1 Wrapper for Delphi 2009 and Delphi 2010 which automatically creates OOP callback f ...

  8. Tornado的一个开源社区

    https://link.zhihu.com/?target=http%3A//www.tornadoweb.org/en/stable/ 基于Tornado的一个开源社区 GitHub - shiy ...

  9. windows下搭建PHP环境

    1.Apache 下载地址:http://httpd.apache.org/download.cgi 下载之后进入CMD,/Apache/bin/httpd.exe -k install 进行安装 提 ...

  10. 解决maven仓库有jar包但是maven程序无法下载仓库jar包

    话说,这个问题困扰了我两个多月了已经~~~ 后来发现不知道被谁动了,把我的仓库没有放到仓库组里面~~~ 用admin登录进去,默认密码是admin123,然后看截图操作吧. (记得删除你本地报错说** ...