Codeforces Round #382 (Div. 2) C. Tennis Championship(斐波那契递推)

题目链接:http://codeforces.com/contest/735/problem/C

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.

Examples
input
2
output
1
input
3
output
2
input
4
output
2
input
10
output
4
Note
In all samples we consider that player number 1 is the winner.

In the first sample, there would be only one game so the answer is 1.

In the second sample, player 1 can consequently beat players 2 and 3.

In the third sample, player 1 can’t play with each other player as after he plays with players 2 and 3 he can’t play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.

【中文题意】问你冠军最多能赢多少场比赛,然后一个人只能和赢得场数最多相差一的人进行比赛,如果一个人输掉了比赛,那么他就失去了继续比赛的资格。
【思路分析】仔细找一下规律不难发现,就是求比这个数小的最大的斐波那契数列的第几项-2。
【AC代码】

#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define LL long long

LL f[200];

void init()
{
    f[0]=0;
    f[1]=1;
    for(int i=2;i<=90;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
}
int main()
{
    long long n;
    while(~scanf("%I64d",&n))
    {
        init();
        int re;
        for(int i=1;i<=200;i++)
        {
            if(f[i]<=n)
            {
                re=i;
            }
            else
            {
                break;
            }
        }
        printf("%d\n",re-2);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值