A. Tennis Championship
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will ben 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 playeddiffers 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 players2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players2 and 3 he can't play against player4, as he has 0 games played, while player1 already played 2. Thus, the answer is2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
题意:n个人在一起打网球比赛,两个人对打。一个人如果输了,就要退出比赛。两个人可以打比赛有个前提条件:两个人的比赛场数的差值不能大于1。问这n个人中打了最多比赛的那个人打了几场比赛。
这题其实就是要自己画个表来找规律。
19=5 20=5 21=6 22=6 23=6 24=6 25=6 26=6 27=6 28=6 29=6 30=6 31=6 32=6 33=6 34=7 35=7 36=7 37=7 38=7 39=7 40=7 41=7 42=7 43=7 44=7 45=7 46=7 47=7 48=7 49=7 50=7 51=7 52=7 53=7 54=7 55=8 56=8 57=8 58=8 59=8 60=8 61=8 62=8 63=8 64=8 65=8 66=8 67=8 68=8 69=8 70=8 71=8 72=8 73=8 74=8 75=8 76=8 77=8 78=8 79=8 80=8 81=8 82=8 83=8 84=8 85=8 86=8 87=8 88=8 89=9 90=9 91=9 92=9
仔细观察节点的话会发现数列是酱紫的:1,2,3,5,8,13........
嗯,没错,这就是个递归数列。。是斐波那契数列。找到规律的话,直接上代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL fib[205];
void FF()
{
fib[0]=0;
fib[1]=1;
for(int i=2;i<=200;i++)
{
fib[i]=fib[i-1]+fib[i-2];
}
}
int main()
{
FF();
LL n;
while(~scanf("%lld",&n))
{
for(int i=0;i<200;i++)
{
if(fib[i]>n)
{
printf("%d\n",i-3);
break;
}
}
}
return 0;
}