Codeforces Round #382 (Div. 1) A. Tennis Championship(递推)

来源:互联网 发布:手机视力测试软件 编辑:程序博客网 时间:2024/05/16 15:13

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,问最后的冠军最多能参加多少比赛。

分析: 设f[i]表示冠军赢得i场比赛至少需要多少人参赛,则f[i] = f[i-1] + f[i-2],就是一个菲波那切数列。

#include<iostream>#include<string>#include<algorithm>#include<cstdlib>#include<cstdio>#include<set>#include<map>#include<vector>#include<cstring>#include<stack>#include<queue>#define INF 0x3f3f3f3f#define eps 1e-9#define N 200005  using namespace std;long long n,f[105];int main(){cin>>n;f[0] = 1,f[1] = 2;for(int i = 2;i <= 105;i++){f[i] = f[i-1] + f[i-2];if(f[i] > n){cout<<i-1<<endl;break;} }}


0 0
原创粉丝点击