POJ2699 The Maximum Number of Strong Kings
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2102 | Accepted: 975 |
Description
![](http://poj.org/images/2699_1.jpg)
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.
![](http://poj.org/images/2699_2.jpg)
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
Source
网络流 最大流
将代表每场比赛的边记为流量图中的点,从S到每场比赛连边,容量为1;
从每个参赛者到T连边,容量为胜利场数。
假设king是胜场最多的前king个人,将参赛者a[]按胜利次数从大到小排序,方便连边。枚举或者二分king数量(n<=10,复杂度没啥差别),对于每场比赛,如果其中一方a是king,且另一方b胜场更多,那么将边强行定向,从比赛到a连边,容量为1(表示胜利);否则a和b都可以胜利,就将边看作双向边,比赛到a、b各连一条边,容量为1。
↑如果能跑满流,那么当前选取的king个数可行。
(测试数据格式似乎很诡异,以下代码中,如果读入方式换成注释掉的部分,本地手测都能过,交上去就WA)
刚开始有另一种设想:
将参赛者拆点,S到每个入点连边,容量为此人胜场a[i],每个出点到T连边,容量为此人负场n-1-a[i]。
枚举king的个数,每多加一个人,就在前一步的参量网络上添边,看网络流能否增广,能就继续加king人数。
但是这种算法在测discuss里的大数据时就挂掉了。
↑姑且记个思路。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define LL long long
using namespace std;
const int mx[]={,,,-,};
const int my[]={,,,,-};
const int mxn=;
int a[mxn],n=;
int cmp(const int q,const int e){return q>e;}
void read(){
char s[];
/* fgets(s,200,stdin);
int len=strlen(s);
for(int i=0;i<len;i++){
int x=0,f=1;char ch=s[i];
while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=s[++i];}
while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=s[++i];}
a[++n]=x;
}*/
gets(s);
int len=strlen(s);
for(int i=;i<len;i++){
if(s[i]>='' && s[i]<='')a[++n]=(s[i]-'');
}
return;
}
struct edge{int v,nxt,f;}e[mxn*mxn*];
int hd[mxn],mct=;
inline void add_edge(int u,int v,int f){
e[++mct].v=v;e[mct].f=f;e[mct].nxt=hd[u];hd[u]=mct;return;
}
inline void ins(int u,int v,int f){add_edge(u,v,f);add_edge(v,u,);return;}
int S,T;
int id[][];
int bct=;
void init(){
memset(hd,,sizeof hd);
n=;mct=;bct=;
return;
}
void init2(){
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
id[i][j]=id[j][i]=++bct;
return;
}
int d[mxn];
bool BFS(){
memset(d,,sizeof d);
queue<int>q;
d[S]=;
q.push(S);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(!d[v] && e[i].f){
d[v]=d[u]+;
q.push(v);
}
}
}
return d[T];
}
int DFS(int u,int lim){
if(u==T)return lim;
int tmp,f=;
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(d[v]==d[u]+ && e[i].f){
tmp=DFS(v,min(lim,e[i].f));
e[i].f-=tmp;
e[i^].f+=tmp;
f+=tmp;
lim-=tmp;
if(!lim)return f;
}
}
d[u]=;
return f;
}
int Dinic(){
int res=;
while(BFS())res+=DFS(S,1e9);
return res;
}
int smm=;
bool solve(int lim){
int i,j;
memset(hd,,sizeof hd);
mct=;
for(i=;i<=smm;i++)ins(S,i,);
for(i=;i<=n;i++)ins(smm+i,T,a[i]);//胜场
int hd=;
for(i=;i<=n;i++)
for(j=;j<=i;j++){
if(i==j)continue;
if(i<=lim && a[i]<a[j])ins(id[i][j],smm+i,);
else{
ins(id[i][j],smm+i,);
ins(id[i][j],smm+j,);
}
}
if(Dinic()==smm)return ;
return ;
}
int m;
int main()
{
scanf("%d\n",&m);
int i,j;
while(m--){
init();//
read();
sort(a+,a+n+,cmp);
init2();
// for(i=1;i<=n;i++)printf("%d ",a[i]);
// printf("\n");
smm=;
for(i=;i<=n;i++)smm+=a[i];
if(smm!=n*(n-)/){printf("0\n");continue;}
smm=n*(n-)/;
S=;T=smm+n+;
int ans=;
for(i=;i<=n;i++){
if(solve(i))ans=i;
else break;
}
printf("%d\n",ans);
}
return ;
}
POJ2699 The Maximum Number of Strong Kings的更多相关文章
- 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(最大流)
枚举所有Strong King的状态(最多1024种左右),然后判断是否合法. 判定合法用网络流,源点-比赛-人-汇点,这样连边. 源点向每场比赛连容量为1的边: 如果一场比赛,A和B,A是Stron ...
- 【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 Description
The Maximum Number of Strong Kings Description A tournament can be represented by a complete graph ...
- 【POJ2699】The Maximum Number of Strong Kings(二分,最大流)
题意: 有n个队伍,两两都有比赛 知道最后每支队伍获胜的场数 求最多有多少队伍,他们战胜了所有获胜场数比自己多的队伍,这些队伍被称为SK N<=50 思路:把每个队伍和它们两两之间的比赛都当做点 ...
- 【poj2699】 The Maximum Number of Strong Kings
http://poj.org/problem?id=2699 (题目链接) 题意 给出1张有向完全图.U->V表示U可以打败V并得一分.如果一个人的得分最高,或者他打败所有比自己得分高的人,那么 ...
- The Maximum Number of Strong Kings
poj2699:http://poj.org/problem?id=2699 题意:n个人,进行n*(n-1)/2场比赛,赢一场则得到一分.如果一个人打败了所有比他分数高的对手,或者他就是分数最高的, ...
- 【POJ】【2699】The Maximum Number of Strong Kings
网络流/最大流/二分or贪心 题目大意:有n个队伍,两两之间有一场比赛,胜者得分+1,负者得分+0,问最多有几只队伍打败了所有得分比他高的队伍? 可以想到如果存在这样的“strong king”那么一 ...
- POJ 2699 The Maximum Number of Strong Kings (最大流+枚举)
http://poj.org/problem?id=2699 题意: 一场联赛可以表示成一个完全图,点表示参赛选手,任意两点u, v之间有且仅有一条有向边(u, v)或( v, u),表示u打败v或v ...
随机推荐
- ASP.NET MVC使用jQuery来POST数据至数据库中
学习ASP.NET MVC程序,结合jQuery客户端代码,Post数据至数据库去.Insus.NET今天写一个完整性的例子. 在数据库中,创建一个表[dbo].[TestUser]: 既然是把数据存 ...
- [转]❲阮一峰❳Linux 守护进程的启动方法
❲阮一峰❳Linux 守护进程的启动方法 "守护进程"(daemon)就是一直在后台运行的进程(daemon). 本文介绍如何将一个 Web 应用,启动为守护进程. 一.问题的由来 ...
- 简单的js验证码
转自:未找到 <script type ="text/javascript" language ="javascript"> var cod ...
- c++游戏服务器编程学习笔记(一)TCP/IP
1. c++游戏服务器编程c++运行效率非常高2. TCP传输控制协议IP网际协议Socket 3.Linux 乌班图开源第三方库BOOST 4.80%游戏服务器端用C++工作量最大的地方是具体的游戏 ...
- 如何用 fiddler 调试线上代码
有时代码上线了,突然就碰到了坑爹的错误.或者有时看别人家线上的代码,对于一个文件想 fork 下来试试效果又不想把全部文件拉到本地,都可以使用 fiddler 的线上调试功能. 比方说我们打开携程的首 ...
- 奇怪的Js时间计算方法,跨多个月后出现1天的误差
在项目中要求用计算两个时间相差的天数,通俗的说就是两个时间 相减, 我的方法 先把两个时间转成相应的毫秒,相减后,再除以(1000 * 60 * 60 * 24) 就可以得到对应天数,但天数会比实际少 ...
- Bootstrap系列 -- 41. 带表单的导航条
有的导航条中会带有搜索表单,在Bootstrap框架中提供了一个“navbar-form”,使用方法很简单,在navbar容器中放置一个带有navbar-form类名的表单.navbar-left”让 ...
- 开发WP版本的大菠萝英雄榜
前言 想当年Team有无数人在玩大菠萝,我被忽悠进来做肉盾,选了蛮子,从1.0开始,经历了103.105.108.2.0.2.1.这个游戏对我最大的帮助是学习了不同的技术,比如XAML.比如xcode ...
- 基于DDS的任意波形发生器
实验原理 DDS的原理 DDS(Direct Digital Frequency Synthesizer)直接数字频率合成器,也可叫DDFS. DDS是从相位的概念直接合成所需波形的一种频率合成技术. ...
- tomcat设置端口号和默认webapp
tomcat一下载,解压之后webapps目录下自带几个webapp: * docs文档:这是一个静态页面集,不用启动tomcat也可以阅读 * examples样例 * hostmanager主机管 ...