[Solution] bike racing problem [AHOI2016] [P2777]

[Solution] bike racing problem [AHOI2016] [P2777]

To force myself to one day simulation questions

Portal: bicycle race \ ([AHOI2016] \) \ ([P2777] \)

Description [title]

The game a total of \ (N \) players, the first day players will receive \ (N \) points points, second place will receive \ (N-1 \) points for third place will receive \ ( N-2 \) points, and so on, the last one will get \ (1 \) points. To ensure that no players will be ranked the same.

In a few days before the contest, \ (N \) players have some points. Now about to begin the final day of competition. Snow would like to know how many players likely to get the ultimate champion, that is to say how many players it is possible to get through the final day cumulative total score first.

[Enter]

A first line of input integer \ (N \) , represents the total number of players.
After \ (N \) line, wherein the first \ (I \) line input an integer \ (B [i] \) represents \ (I \) accumulated points of the players has been obtained.

[Output]

Output An integer indicates how many players likely to get the ultimate champion.

[Sample \ (1 \) ]

样例输入:
3
8
10
9

样例输出:
3

[Sample \ (2 \) ]

样例输入:
5
15
14
15
12
14

样例输出:
4

【data range】

\(100\%\) \(3 \leqslant N \leqslant 3e5\) \(,\) \(0 \leqslant b[i] \leqslant 2e6\)


【analysis】

First row a sequence?

If you want a person to win the championship, then let him take the last day of the most time-sharing, the possibility that he was the greatest champion, may wish to set it as the highest score, while other people grab basis points lower than his affirmation less than championship the focus is the basis points higher than see if I can grab him.
Set up the final day basis points higher to get low scores, low basal low to get better, and then see if the maximum value among them is greater than the man we want for the championship for the total score, if more than directly for the next attempt, If it is less than \ (ANS ++ \) .

Look at the second sample:

After sorting became Jiang Zi:

If you want for the first person, and association score calculation:

The second person was found higher score than him, skip, for the next person. If you want to for a second person, then the first not give what he does not matter the score, but the three men behind to try to score that is smaller \ (1,2,3 \) , so that the corresponding down:

Found that less than a second behind the funny person, so dedicated to success.

And so on, find any one person to worship before him, is always that one does not change the score, so you can use an array of \ (f [\) \ (] \) to advance the pre-behind everyone who the maximum total score, when to worship someone \ (i \) when the direct use of \ (f [i] \) and \ (a [i] + n \) to compare the size and statistical answer to.

【Code】

#include<algorithm>
#include<cstdio>
#define Re register int
using namespace std;
const int N=3e5+3;
int n,ans,a[N],Q[N],f[N];
inline void in(Re &x){
    int fu=0;x=0;char c=getchar();
    while(c<'0'||c>'9')fu|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    x=fu?-x:x;
}
int main(){
    in(n);
    for(Re i=1;i<=n;++i)in(a[i]);
    sort(a+1,a+n+1);
    for(Re i=n;i>=1;--i)Q[i]=a[i]+n-i+1;
    f[n]=-1e9;
    for(Re i=n-1;i>=1;--i)f[i]=max(f[i+1],Q[i+1]);
    for(Re i=1;i<=n;++i)ans+=f[i]<=a[i]+n;
    printf("%d",ans);
}

Guess you like

Origin www.cnblogs.com/Xing-Ling/p/10963983.html