codeforces 735 C. Tennis Championship (数学)
2016-12-17 22:40
471 查看
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
output
input
output
input
output
input
output
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,问最后赢的人最多能参加多少次
假设赢x场,由于每场双方赢的次数不超过1 ,那么f[x]=f[x-1]+f[x-2](也就是赢x-1场的人和赢x-2场的人对打),规律遵循斐波那契数列
然后二分遍历n>=f[x]时最大的x值。
code:
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,问最后赢的人最多能参加多少次
假设赢x场,由于每场双方赢的次数不超过1 ,那么f[x]=f[x-1]+f[x-2](也就是赢x-1场的人和赢x-2场的人对打),规律遵循斐波那契数列
然后二分遍历n>=f[x]时最大的x值。
code:
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL __int64int main()
{
LL n,f[110];
f[1]=2;f[2]=3;
int i;
for(i=3;;i++)//f[100]超long long ;f[50]超int
{
f[i]=f[i-1]+f[i-2];
if(f[i]>=1e18)
break;
}
scanf("%I64d",&n);
LL l=0,r=i,mid,ans;
while(l<=r)
{
mid=(l+r)/2;
if(f[mid]>n)
{
r=mid-1;
}
else
{
ans=mid;
l=mid+1;
}
}
printf("%I64d\n",ans);
return 0;
}
相关文章推荐
- codeforces 735-D. Taxes(数学)
- codeforces 735 D Taxes(数学)
- codeforces 735 D. Taxes (数学)
- Codeforces 650A 数学简单题
- 【codeforces 680 C】【数学题+交互题】C. Bear and Prime 1【底数是[2,100]中的数,现在你最多询问20次,询问为这个数是不是底数的因数,最后判断这个数是不是素数】
- Codeforces 448D: Multiplication Table(二分+数学)
- Codeforces 886E (Codeforces Round #445) Maximum Element 组合数学+DP
- codeforces 894E - Ralph and Mushrooms tarjan缩点+数学+记忆化搜索找最长路
- codeforces 702D D. Road to Post Office(数学)
- Non-square Equation CodeForces - 233B (数学)
- Codeforces 550C Divisibility by Eight【数学思维题】好题!
- CodeForces 111B - Petya and Divisors- 暴力-数学
- codeforces 141-B. Hopscotch(数学)
- CodeForces - 899D Shovel Sale 数学+思维
- CodeForces - 554C Kyoya and Colored Balls (组合数学&逆元模板)
- codeforces 380D. Sereja and Cinema(#223div1 组合数学)
- codeforces 900D(组合数学+剪枝)
- codeforces-678-C. Joty and Chocolate(数学)
- CodeForces 468A. 24 Game(数学构造)
- Codeforces 592C The Big Race【数学啊】