Codeforces#382(Div. 2) C.Tennis Championship【递推】

在遵循特定比赛规则的前提下,本文探讨如何安排巴西里约热内卢举办的网球锦标赛,以确保冠军选手能参与最多的比赛场次。通过分析比赛规则及采用斐波那契数列的解决方案,文章提供了一个有效的方法来确定最大可能的比赛数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C. Tennis Championship
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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.

题目大意:

一共N个人,要进行比赛,我们现在需要达到的目的是,将最终的获胜者的参加比赛的场数最多。

比赛规则是:如果两个人的胜场数相差最对值小于等于1,这两人就可以进行一场比赛。

比赛没有平手,只有获胜。


思路:


1、首先递推出以下所有情况的正解:

人数23456789101112
12233344444

2、接下来观察到解为1的个数为1,解为2的个数为2,解为3的个数为3,解为4的个数为5.很明显的斐波那契数列,那么接下来维护一个斐波那契数列的前缀和即可。

(预处理到95即可)


Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
#define ll __int64
ll f[100];
void init()
{
    memset(f,0,sizeof(f));
    f[1]=1;
    f[2]=2;
    for(int i=3;i<=95;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    for(int i=1;i<=95;i++)
    {
        f[i]=f[i-1]+f[i];
    }
}
int main()
{
    init();
    ll n;
    while(~scanf("%I64d",&n))
    {
        n-=2;
        for(int i=1;i<=95;i++)
        {
            if(f[i]>n)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值