0
点赞
收藏
分享

微信扫一扫

Codeforces Round #382 (Div. 2) -- C. Tennis Championship (数学找规律 -- 斐波那契数列)


大体题意:

n 个人进行比赛,问你一个做多打多少场比赛? 两个人进行比赛,它们比赛场次之差不差过1,否则不能打,一旦一个人打比赛输了,就不能继续往后打了!

思路:

很水的一道题目,想复杂了!

其实是一个找规律的题目。

当你写出几个数据来后,就能猜出来了:

2 3 4 5 6 7 8 9 10 11 12 13

1 2 2 3 3 3 4 4  4  4  4   5

下面同一类的个数   恰好构成斐波那契数列!

详细见代码:


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100];
void init(){
    a[1] = 1;
    a[2] = 2;
    for (int i = 3; i <= 100; ++i) a[i] = a[i-1] + a[i-2];
}
int main(){
    ll n;
    init();
    while(~scanf("%lld",&n)){
        ll sum = 0;
        --n;
        for (int i = 1; i <= 100; ++i){
            sum += a[i];
            if (sum >= n) {
                printf("%d\n",i);
                break;
            }
        }
    }


    return 0;
}




C. Tennis Championship



time limit per test



memory limit per test



input



output



n

differs by no more than one

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



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



1

1.

1 can consequently beat players 2 and 3.

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)








举报

相关推荐

0 条评论