Codeforces Round #382 (Div. 2) C. Tennis Championship 斐波那契
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.
The only line of the input contains a single integer n (2 ≤ n ≤ 1018) — the number of players to participate in the tournament.
Print the maximum number of games in which the winner of the tournament can take part.
2
1
3
2
4
2
10
4
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的比赛,问一个赢的人最多比几次;
思路:显然4需要跟3比才能得到5,相当于n-1需要跟n-2比得到n,不就是一个菲薄那契么,暴力求解就好了;
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define esp 0.00000000001 const int N=1e5+10,M=1e6+10,inf=1e9; const ll INF=1e18+10; ll a[100]; int main() { a[1]=2; a[2]=3; for(int i=3;i<=85;i++) a[i]=a[i-1]+a[i-2]; ll x; scanf("%lld",&x); for(int i=85;i>=1;i--) if(x>=a[i]) { printf("%d\n",i); return 0; } return 0; }