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 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
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
typedef long long LL;
const int MAXN=105;
int s[15],id[105][105],v[105][105],cnt1,cnt2;
char str[25];
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=0;i<100;i++)G[i].clear();
        edges.clear();
    }
    void addedge(int from,int to,int cap)
    {
        edges.push_back((Edge){from,to,cap,0});
        edges.push_back((Edge){to,from,0,0});
        int m=edges.size();
        G[from].push_back(m-2);
        G[to].push_back(m-1);
    }
    bool bfs()
    {
        memset(vis,0,sizeof(vis));
        queue<int>q;
        q.push(s);
        d[s]=0;
        vis[s]=1;
        while(!q.empty())
        {
            int x=q.front();q.pop();
            for(int i=0;i<G[x].size();i++)
            {
                Edge& e=edges[G[x][i]];
                if(!vis[e.to]&&e.cap>e.flow)
                {
                    vis[e.to]=1;
                    d[e.to]=d[x]+1;
                    q.push(e.to);
                }
            }
        }
        return vis[t];
    }
    int dfs(int x,int a)
    {
        if(x==t||a==0)return a;
        int flow=0,f;
        for(int& i=cur[x];i<G[x].size();i++)
        {
            Edge& e=edges[G[x][i]];
            if(d[x]+1==d[e.to]&&(f=dfs(e.to,min(a,e.cap-e.flow)))>0)
            {
                e.flow+=f;
                edges[G[x][i]^1].flow-=f;
                flow+=f;
                a-=f;
                if(a==0)break;
            }
        }
        return flow;
    }
    int maxflow(int s,int t)
    {
        this->s=s,this->t=t;
        int flow=0;
        while(bfs())
        {
            memset(cur,0,sizeof(cur));
            flow+=dfs(s,2e5+5);
        }
        return flow;
    }
}dc;
bool check(int x)
{
    dc.init();
    memset(v,0,sizeof(v));
    for(int i=1;i<=cnt1;i++)
        dc.addedge(0,i,s[i]);
    for(int i=1;i<=x;i++)
        for(int j=i+1;j<=x;j++)
            if(s[i]>s[j])
                dc.addedge(j,id[i][j],1),v[i][j]=1;
    for(int i=1;i<=cnt1;i++)
        for(int j=i+1;j<=cnt1;j++)
        {
            dc.addedge(id[i][j],cnt1+cnt2+1,1);
            if(!v[i][j])
                dc.addedge(i,id[i][j],1),dc.addedge(j,id[i][j],1);
        }
    return dc.maxflow(0,cnt1+cnt2+1)==cnt1*(cnt1-1)/2;
}
int main()
{
    int T;
    scanf("%d",&T);
    getchar();
    while(T--)
    {
        gets(str);
        cnt1=cnt2=0;
        for(int i=0,len=strlen(str);i<len;i++)
            if(str[i]!=‘ ‘)
                s[++cnt1]=(int)str[i]-‘0‘;
        for(int i=1;i<=cnt1/2;i++)
            swap(s[i],s[cnt1-i+1]);
        for(int i=1;i<=cnt1;i++)
            for(int j=i+1;j<=cnt1;j++)
                id[i][j]=++cnt2+cnt1;
        for(int i=cnt1;i>=1;i--)
            if(check(i))
            {
                printf("%d\n",i);
                break;
            }
    }
    return 0;
}
时间: 2024-10-15 10:11:13

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打败u.一个选手的得分等于被他打败的选手总数.一个选手被称为“strong king”当且仅当他打败了所有比他分高的选手.分数最高的选手也是strong king.现在给出某场联赛所有选手的得分序列,由低到高,问合理安排每场比赛的结果后最多能有几个strong king.已知选手总数不超过10个.

POJ 2699 The Maximum Number of Strong Kings 竞赛图+最大流

题目大意:有n个人之间互相竞赛,现在给出每个人赢了多少局.若定义一个人是最高分或者这个人赢了所有比他分高的人,那么这个人就算赢了.问最多可能有多少人赢. 思路:最大流模型的另一种应用.二分图,左边是所有选手,右边是所有比赛. S->所有选手 f:该选手赢了多少局 所有比赛->T f:1 由于最多只有十个人,所以枚举答案就行了.枚举最多有多少人赢了,如果一个分比较低的人赢了,那么分比他高的人必定也可以赢,所以就假设是分数最高的n个人赢了. 在这些人之间的竞赛需要保证分低的人赢了分高的人,那么 i

解题报告 之 POJ2699 The Maximum Number of Strong Kings

解题报告 之 POJ2699 The Maximum Number of Strong Kings 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 t

POJ2699 The Maximum Number of Strong Kings

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2102   Accepted: 975 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

【POJ2699】The Maximum Number of Strong Kings

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 playe

POJ2699_The Maximum Number of Strong Kings

这题目,,,真是...诶.坑了好久. 给一个有向图.U->V表示U可以打败V并得一分. 如果一个人的得分最高,或者他打败所有比自己得分高的人,那么此人就是king. 现在给出每个人的得分,求最多可能有多少个king同时存在. 可以证明,如果有k个人是king,那么至少有一种分配方案使得这k个king都是分数最高的那k个人.(证明略,想想就知道了) 于是我们可以开始枚举从i个人开始,后面的都是king. 除了源点和汇点以外,还有两种点,一种表示人(n),一种表示比赛(n*(n/2)/2). 如果一

【POJ】【2699】The Maximum Number of Strong Kings

网络流/最大流/二分or贪心 题目大意:有n个队伍,两两之间有一场比赛,胜者得分+1,负者得分+0,问最多有几只队伍打败了所有得分比他高的队伍? 可以想到如果存在这样的“strong king”那么一定是胜场较多的队伍……(比他赢得多的队伍num少,而他总共赢得场数times足够多,至少得满足times>=num吧?) 那么我们可以二分/枚举k,表示胜场前k多的队伍是stong king.(这题范围小,只有10支队伍,如果队伍较多我们就需要二分了……) 最最丧心病狂的是!!!出题人TMD卡读入!

The Maximum Number of Strong Kings

poj2699:http://poj.org/problem?id=2699 题意:n个人,进行n*(n-1)/2场比赛,赢一场则得到一分.如果一个人打败了所有比他分数高的对手,或者他就是分数最高的,那么他就是strong kind.现在给你每个人的得分,问你最多有多少个strong kind. 题解:自己没有思路,看了别人的题解,才勉强理解了.首先,肯定让得分高的成为strong king,因为概率比较大,然后就是怎建图了.假如,我们已经知道了,有m个strong kind,那么这m个人一定是

【poj2699】 The Maximum Number of Strong Kings

http://poj.org/problem?id=2699 (题目链接) 题意 给出1张有向完全图.U->V表示U可以打败V并得一分.如果一个人的得分最高,或者他打败所有比自己得分高的人,那么此人就是king.现在按顺序给出每个人的得分,求最多可能有多少个king同时存在. Solution 想了半天贪心,然而得分相等的情况真的很不好处理..真的没想到是最大流..左转题解:http://blog.csdn.net/sdj222555/article/details/7797257 考虑这样建图