The Maximum Number of Strong Kings

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2488   Accepted: 1131

题目链接http://poj.org/problem?id=2699

Description:

A tournament can be represented by a complete graph in which each vertex denotes a player and a directed edge is from vertex x to vertex y if player x beats player y. For a player x in a tournament T, the score of x is the number of players beaten by x. The score sequence of T, denoted by S(T) = (s1, s2, . . . , sn), is a non-decreasing list of the scores of all the players in T. It can be proved that S(T) = (s1, s2, . . . , sn) is a score sequence of T if and only if 
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:

The first line of the input file contains an integer m, m <= 10, which represents the number of test cases. The following m lines contain m score sequences in which each line contains a score sequence. Note that each score sequence contains at most ten scores.

Output:

The maximum number of strong kings for each test case line by line.

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

题意:

多组数据,然后对于每组数据给出每个人击败的人数,为最多有多少人是强者。

强者的定义为:得到的分数最多 or 击败所有分数比他高的人。这里每击败一个人都可以得一分。

题解:

这题orz...没有想出来。但最后看了题解后发现就是个公平分配问题。

我们建图时比赛在左边,人在右边。每场比赛连两个人,代表这两个人在比赛,然后每场比赛只会分配1的流出去,代表哪个人获胜。

这就是我们建图的大体思路。

由于人数很少,所以我们可以枚举来确定强者,那么怎么确定呢,直接二进制表示的话复杂度太高。

通过证明可以发现,分数越高的人越有可能成为强者,简要证明过程如下:

假设分数为: ...i j k ......,这里i和k时强者,而j不是。如果i是强者,那么说明i打败了后面的所有人,而j不是强者,则说明他可能输给了后面的某几个人。

因为j的分数比i的分数高,说明j多欺负了几个弱者。那么现在我们让j赢回高分的人,让i去赢前面多欺负的那几个人,此时i可能会输给比他强的人,此时满足赢的数量和之前一样。相当于换了人去欺负那些弱者。这样j也可以变为强者了。

以上就是简略的一个证明,只要保证每个人的分数不变就ok。

然后我们从分数大开始枚举,在建图时,源点连接比赛,容量为1;人连接汇点,容量为他能赢的最多次数。

比赛连接两个人时,如果一个人是强者并且另一个人分数比他高,那么只能强者赢;否则哪个赢都可以。对赢的那个人连接容量为1的边。

最后跑个最大流看看比赛能否比完就行了(我这里是通过是否每个人的分数能够符合题意来判断的)。

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#define s 0
#define t 200
#define INF 0x3f3f3f3f
#define st n*(n-1)/2
using namespace std;
typedef long long ll;
const int N = ;
int T;
char str[N];
int a[N],vis[N],head[N],d[N];
int ans,tot,mx,n,sum;
struct Edge{
int v,c,next;
}e[N*N];
void adde(int u,int v,int c){
e[tot].v=v;e[tot].next=head[u];e[tot].c=c;head[u]=tot++;
e[tot].v=u;e[tot].next=head[v];e[tot].c=;head[v]=tot++;
}
void build(){
memset(head,-,sizeof(head));tot=;
for(int i=;i<=st;i++) adde(s,i,);
int fir = st+,last = st+;
for(int i=;i<=st;i++){
if(vis[fir]&&a[last-st]>a[fir-st]){
adde(i,fir,);adde(i,last,);
}else if(vis[last]&&a[last-st]<a[fir-st]){
adde(i,fir,);adde(i,last,);
}else{
adde(i,fir,);adde(i,last,);
}
last++;
if(last>st+n){
fir++;last=fir+;
}
}
for(int i=st+;i<=st+n;i++) adde(i,t,a[i-st]);
}
bool bfs(int S,int T){
memset(d,,sizeof(d));d[S]=;
queue <int > q;q.push(S);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(!d[v] && e[i].c>){
d[v]=d[u]+;
q.push(v);
}
}
}
return d[T]!=;
}
int dfs(int S,int a){
int flow=,f;
if(S==t || a==) return a;
for(int i=head[S];i!=-;i=e[i].next){
int v=e[i].v;
if(d[v]!=d[S]+) continue ;
f=dfs(v,min(a,e[i].c));
if(f){
e[i].c-=f;
e[i^].c+=f;
flow+=f;
a-=f;
if(a==) break;
}
}
if(!flow) d[S]=-;
return flow;
}
int Dinic(){
int max_flow=;
while(bfs(,t)) max_flow+=dfs(,INF);
return max_flow;
}
int main(){
cin>>T;
getchar();
while(T--){
memset(vis,,sizeof(vis));
gets(str);
mx=n=sum=;ans=-;
int len = strlen(str);
for(int i=;i<len;i++)
if(str[i]<='' && str[i]>='')
a[++n]=str[i]-'',mx = max(mx,a[n]),sum+=a[n];
for(int i=n;i>=;i--){
if(a[i]==mx) continue ;
vis[i+st]=;
build();
int max_flow=Dinic();
if(max_flow<sum){
ans=n-i;
break ;
}
}
if(ans==-) ans=n;
cout<<ans<<endl;
}
return ;
}

POJ2699:The Maximum Number of Strong Kings(枚举+贪心+最大流)的更多相关文章

  1. POJ2699 The Maximum Number of Strong Kings

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2102   Accepted: 975 Description A tour ...

  2. POJ2699 The Maximum Number of Strong Kings(最大流)

    枚举所有Strong King的状态(最多1024种左右),然后判断是否合法. 判定合法用网络流,源点-比赛-人-汇点,这样连边. 源点向每场比赛连容量为1的边: 如果一场比赛,A和B,A是Stron ...

  3. poj 2699 The Maximum Number of Strong Kings 枚举 最大流

    题目链接 题意 对于一个竞赛图(有向完全图),其顶点是选手,边是比赛,边\(e=(u,v)\)代表该场比赛中\(u\)战胜\(v\). 现定义选手的分数为其战胜的人的个数(即竞赛图中点的出度).并且定 ...

  4. 【POJ2699】The Maximum Number of Strong Kings(网络流)

    Description A tournament can be represented by a complete graph in which each vertex denotes a playe ...

  5. 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 ...

  6. 【POJ2699】The Maximum Number of Strong Kings(二分,最大流)

    题意: 有n个队伍,两两都有比赛 知道最后每支队伍获胜的场数 求最多有多少队伍,他们战胜了所有获胜场数比自己多的队伍,这些队伍被称为SK N<=50 思路:把每个队伍和它们两两之间的比赛都当做点 ...

  7. POJ 2699 The Maximum Number of Strong Kings (最大流+枚举)

    http://poj.org/problem?id=2699 题意: 一场联赛可以表示成一个完全图,点表示参赛选手,任意两点u, v之间有且仅有一条有向边(u, v)或( v, u),表示u打败v或v ...

  8. POJ - 2699 The Maximum Number of Strong Kings (最大流+枚举)

    题意:有n(n<=10)个选手,两两之间打比赛,共有n*(n-1)/2场比赛,赢一场得1分.给出每个人最后的得分.求有多少个定义如下的strong king:赢了所有得分比自己高的人或本身就是分 ...

  9. poj 2699 The Maximum Number of Strong Kings【最大流+枚举】

    因为n很小所以从大到小枚举答案.(从小到大先排个序,因为显然胜利场次越多越容易成为strong king.然后对于每个枚举出来的ans建图.点分别表示人和比赛.s向所有人连接流量为胜利场次的边,所有比 ...

随机推荐

  1. ctf题目writeup(8)

    2019.2.11 南京邮电的ctf平台: 地址http://ctf.nuptzj.cn/challenges# 他们好像搭新的平台了...我注册弄了好半天... 1. 签到题,打开网址: 查看一下页 ...

  2. 多线程编程之Apue3rd_Chapter11之互斥锁_读写锁_自旋锁

    学习了apue3rd的第11章,主要讲的是多线程编程.因为线程共享进程的资源比如堆和全局变量,多线程编程最重要的是,使用各种锁进行线程同步. 线程编程首先要学习的三个函数如下: #include &l ...

  3. Python3爬虫(十一) 爬虫与反爬虫

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.重要概念 二.爬虫反爬虫进化论

  4. P1107 最大整数

    P1107 最大整数 题目描述 设有n个正整数 (n<=20), 将它们连接成一排, 组成一个最大的多位整数. 例如: n=3时, 3个整数13, 312, 343连接成的最大整数为: 3433 ...

  5. Django-Content-type用法

    from django.db import models from django.contrib.contenttypes.models import ContentType from django. ...

  6. python 基础篇 11 函数进阶----装饰器

    11. 前⽅⾼能-装饰器初识本节主要内容:1. 函数名的运⽤, 第⼀类对象2. 闭包3. 装饰器初识 一:函数名的运用: 函数名是一个变量,但他是一个特殊变量,加上括号可以执行函数. ⼆. 闭包什么是 ...

  7. LSTM调参经验

    0.开始训练之前先要做些什么? 在开始调参之前,需要确定方向,所谓方向就是确定了之后,在调参过程中不再更改 1.根据任务需求,结合数据,确定网络结构. 例如对于RNN而言,你的数据是变长还是非变长:输 ...

  8. HDU 1693 Eat the Trees(插头DP,入门题)

    Problem Description Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a ...

  9. [整理]docker内部时区修改的两种方法

    方法一 终端执行 date命令,查看宿主服务器的时区是否正确 如果正确: 执行 docker cp /etc/localtime 容器ID:/etc/localtime 将本地时间拷贝到docker内 ...

  10. Python调用MySQL的一些用法小结

    目标:1个excel表内容导入到数据库中,例如:原始excel文件为 aaa.xls 首先:将aaa.xls 转换成aaa.txt ,注意当文件中含有中文字符时,可以通过notepad++打开,在“格 ...