codeforces 735C/382.2.C Tennis Championship

来源:互联网 发布:share软件下载 编辑:程序博客网 时间:2024/05/18 14:14
C. Tennis Championship
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.

Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.

Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.

Input
The only line of the input contains a single integer n (2 ≤ n ≤ 1018) — the number of players to participate in the tournament.

Output

Print the maximum number of games in which the winner of the tournament can take part.

题意:一个选手只能和一个比赛次数与他的比赛次数的差的绝对值不超过一的人比赛,求冠军最多能进行多少把比赛。

思路:不要只往人数上想,可以往场数上想:

           赢 1 把: 至少要 2 个人:

                 2把:              3个人,

                 3把:至少为  至少2把的人数+至少1把的人数。

                 4把:至少为  至少3把的+ 至少2把的(因为比赛次数差不能超过1)。

                  i 把:d[i-1]+d[i-2];

都知道Fibonacci数列很大,所以最多不会超过90把,所以把d[i]全部算出找就行。

#include <iostream>#include<stdio.h>#include<math.h>#include<string.h>#define siz 100005#define inf 1E18using namespace std;__int64 n,a[siz],d[siz];int main(){    __int64 ix=1;    d[1]=2, d[2]=3;    for(ix=3;; ix++)    {        d[ix]=d[ix-1]+d[ix-2];        if(d[ix]>=inf) break;    }    while(scanf("%I64d",&n)!=EOF)    {        int ans;        for(int i=1;i<=ix;i++)        {            if(n<=d[i]){                ans=i;                if(n!=d[i]) ans--;                break;            }        }        cout<<ans<<endl;    }    return 0;}


0 0
原创粉丝点击