POJ 2699 The Maximum Number of Strong Kings Description
The Maximum Number of Strong Kings
Description
for k = 1, 2, . . . , n and equality holds when k = n. A player x in a tournament is a strong king if and only if x beats all of the players whose scores are greater than the score of x. For a score sequence S, we say that a tournament T realizes S if S(T) = S. In particular, T is a heavy tournament realizing S if T has the maximum number of strong kings among all tournaments realizing S. For example, see T2 in Figure 1. Player a is a strong king since the score of player a is the largest score in the tournament. Player b is also a strong king since player b beats player a who is the only player having a score larger than player b. However, players c, d and e are not strong kings since they do not beat all of the players having larger scores.
The purpose of this problem is to find the maximum number of strong kings in a heavy tournament after a score sequence is given. For example,Figure 1 depicts two possible tournaments on five players with the same score sequence (1, 2, 2, 2, 3). We can see that there are at most two strong kings in any tournament with the score sequence (1, 2, 2, 2, 3) since the player with score 3 can be beaten by only one other player. We can also see that T2 contains two strong kings a and b. Thus, T2 is one of heavy tournaments. However, T1 is not a heavy tournament since there is only one strong king in T1. Therefore, the answer of this example is 2.
Input
Output
Sample Input
5
1 2 2 2 3
1 1 3 4 4 4 4
3 3 4 4 4 4 5 6 6 6
0 3 4 4 4 5 5 5 6
0 3 3 3 3 3
Sample Output
2
4
5
3
5
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
typedef long long LL;
const int MAXN=;
int s[],id[][],v[][],cnt1,cnt2;
char str[];
struct dinic
{
struct Edge
{
int from,to,cap,flow;
Edge(){}
Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f){};
};
int s,t,d[MAXN],cur[MAXN];
bool vis[MAXN];
vector<Edge>edges;
vector<int>G[MAXN];
inline void init()
{
for(int i=;i<;i++)G[i].clear();
edges.clear();
}
void addedge(int from,int to,int cap)
{
edges.push_back((Edge){from,to,cap,});
edges.push_back((Edge){to,from,,});
int m=edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
}
bool bfs()
{
memset(vis,,sizeof(vis));
queue<int>q;
q.push(s);
d[s]=;
vis[s]=;
while(!q.empty())
{
int x=q.front();q.pop();
for(int i=;i<G[x].size();i++)
{
Edge& e=edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow)
{
vis[e.to]=;
d[e.to]=d[x]+;
q.push(e.to);
}
}
}
return vis[t];
}
int dfs(int x,int a)
{
if(x==t||a==)return a;
int flow=,f;
for(int& i=cur[x];i<G[x].size();i++)
{
Edge& e=edges[G[x][i]];
if(d[x]+==d[e.to]&&(f=dfs(e.to,min(a,e.cap-e.flow)))>)
{
e.flow+=f;
edges[G[x][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,2e5+);
}
return flow;
}
}dc;
bool check(int x)
{
dc.init();
memset(v,,sizeof(v));
for(int i=;i<=cnt1;i++)
dc.addedge(,i,s[i]);
for(int i=;i<=x;i++)
for(int j=i+;j<=x;j++)
if(s[i]>s[j])
dc.addedge(j,id[i][j],),v[i][j]=;
for(int i=;i<=cnt1;i++)
for(int j=i+;j<=cnt1;j++)
{
dc.addedge(id[i][j],cnt1+cnt2+,);
if(!v[i][j])
dc.addedge(i,id[i][j],),dc.addedge(j,id[i][j],);
}
return dc.maxflow(,cnt1+cnt2+)==cnt1*(cnt1-)/;
}
int main()
{
int T;
scanf("%d",&T);
getchar();
while(T--)
{
gets(str);
cnt1=cnt2=;
for(int i=,len=strlen(str);i<len;i++)
if(str[i]!=' ')
s[++cnt1]=(int)str[i]-'';
for(int i=;i<=cnt1/;i++)
swap(s[i],s[cnt1-i+]);
for(int i=;i<=cnt1;i++)
for(int j=i+;j<=cnt1;j++)
id[i][j]=++cnt2+cnt1;
for(int i=cnt1;i>=;i--)
if(check(i))
{
printf("%d\n",i);
break;
}
}
return ;
}
POJ 2699 The Maximum Number of Strong Kings Description的更多相关文章
- POJ 2699 The Maximum Number of Strong Kings (最大流+枚举)
http://poj.org/problem?id=2699 题意: 一场联赛可以表示成一个完全图,点表示参赛选手,任意两点u, v之间有且仅有一条有向边(u, v)或( v, u),表示u打败v或v ...
- POJ - 2699 The Maximum Number of Strong Kings (最大流+枚举)
题意:有n(n<=10)个选手,两两之间打比赛,共有n*(n-1)/2场比赛,赢一场得1分.给出每个人最后的得分.求有多少个定义如下的strong king:赢了所有得分比自己高的人或本身就是分 ...
- poj 2699 The Maximum Number of Strong Kings 枚举 最大流
题目链接 题意 对于一个竞赛图(有向完全图),其顶点是选手,边是比赛,边\(e=(u,v)\)代表该场比赛中\(u\)战胜\(v\). 现定义选手的分数为其战胜的人的个数(即竞赛图中点的出度).并且定 ...
- poj 2699 The Maximum Number of Strong Kings【最大流+枚举】
因为n很小所以从大到小枚举答案.(从小到大先排个序,因为显然胜利场次越多越容易成为strong king.然后对于每个枚举出来的ans建图.点分别表示人和比赛.s向所有人连接流量为胜利场次的边,所有比 ...
- POJ 2699 The Maximum Number of Strong Kings ——网络流
一定存在一种最优方案,使得分数前几个人是SK 所以我们可以二分答案或者枚举,然后就是经典的网络流建模. 另:输入很Excited #include <cstdio> #include &l ...
- POJ2699:The Maximum Number of Strong Kings(枚举+贪心+最大流)
The Maximum Number of Strong Kings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2488 ...
- POJ2699 The Maximum Number of Strong Kings
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2102 Accepted: 975 Description A tour ...
- 【POJ2699】The Maximum Number of Strong Kings(网络流)
Description A tournament can be represented by a complete graph in which each vertex denotes a playe ...
- 【POJ】【2699】The Maximum Number of Strong Kings
网络流/最大流/二分or贪心 题目大意:有n个队伍,两两之间有一场比赛,胜者得分+1,负者得分+0,问最多有几只队伍打败了所有得分比他高的队伍? 可以想到如果存在这样的“strong king”那么一 ...
随机推荐
- AsyncTask 轻量级的异步类
初步:http://www.cnblogs.com/devinzhang/archive/2012/02/13/2350070.html 详细:http://blog.csdn.net/liuhe68 ...
- 异步上传文件,ajax上传文件,jQuery插件之ajaxFileUpload
http://www.cnblogs.com/kissdodog/archive/2012/12/15/2819025.html 一.ajaxFileUpload是一个异步上传文件的jQuery插件. ...
- 【转载】IIS7.5(经典模式)访问静态资源(.css和.js文件)提示:未能执行 URL
IIS7.5(经典模式)静态资源(.css和.js文件)提示:未能执行 URL “/”应用程序中的服务器错误. 未能执行 URL. 说明: 执行当前 Web 请求期间,出现未处理的异常.请检查堆栈跟踪 ...
- mac10.9下eclipse的storm开发环境搭建
--------------------------------------- 博文作者:迦壹 博客地址:http://idoall.org/home.php?mod=space&uid=1& ...
- [转]win7下apache2.4响应很慢解决方法
win7下apache2.4响应很慢解决方法 PS.按照以下方法测试了以下,似乎确实快了一点[skysowe] 转载自: http://blog.sina.com.cn/s/blog_75ad1010 ...
- 一台机器运行多个JBoss 4.2.3多实例,或多个同一版
http://www.java123.net/v/426419.html 暂未验证 今天应用更新,放到测试服务器上打算测试.测试服务器上有个jboss4.2.3有项目在跑,我是功能改造又不想影 ...
- 非归档模式下使用Rman进行备份和恢复
实验环境: 一.首先进行全库数据备份: 在非归档模式下,rman备份需要在mount模式下进行 SQL> select status from v$instance; STATUS ------ ...
- phonegap文件,目录操作以及网络上传,下载文件(含demo)
正在做一个跨平台的应用,需要使用phonegap进行文件的一些基本操作. 需求如下:可以选择本地图片,或者从相机选择图片,并进行显示在本地,然后上传到服务器,以及可以从服务器下载图片显示出来,如果本地 ...
- Haproxy+asp.net +RedisSessionStateProvider 完美实现负载均衡,并且session保持
.net framework 4.5下测试成功,使用RedisSessionStateProvider 2.2.1保持session数据,通过Haproxy保持会话数据.首先在PM下安装RedisSe ...
- CentOS 7 yum安装Zabbix
一.Zabbix简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统 ...