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
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的人打,问最后比赛最多次的人比赛了几场?

我们可以清楚 如果一个人要赢k场,那么他必须先赢k-1场,同时在打败一个赢了k-2场的人,所以我们可以清楚地发现这是一个斐波那契数列

所以我们先打表,然后找到小于等于n的是第几位就好了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; int main()
{
long long n;
long long int a[91];
a[0]=0;
a[1]=2;
a[2]=3;
for(int i=3;i<=90;i++)
a[i]=a[i-1]+a[i-2];
while(~scanf("%I64d",&n))
{
int cnt=lower_bound(a,a+90,n)-a;
cnt--;
for(int i=1;i<=90;i++)
if(n==a[i])
cnt++;
cout<<cnt<<endl;
}
return 0;
}

最新文章

  1. SQL知识整理二:锁、游标、索引
  2. div加jquery实现iframe标签的功能
  3. 不知道数据库中表的列类型的前提下,使用JDBC正确的取出数据
  4. 将公司的主要项目从eclipse迁移到android studio for mac环境(1)
  5. 黄聪:手机移动端建站Jquery+CSS3+HTML5触屏滑动特效插件、实现触屏焦点图、图片轮展图
  6. CentOS 6.4 64位 安装 mysql 5.6.24
  7. hdu 3345 War Chess
  8. MongoDB学习笔记(四)
  9. st9720-GB 中文编码对照表
  10. Java实现递增数组的二分查找
  11. sweetalert提示框
  12. 细说Redis(一)之 Redis的数据结构与应用场景
  13. three.js学习:三维空间下的直线
  14. jsp页面\n换行替换
  15. Linux内核分析第一周总结
  16. MONGOOSE – 让NODE.JS高效操作MONGODB(转载)
  17. VUE 使用之:nextTick
  18. gattAttribute_t 含义 中文解释
  19. HDU 4462 DFS
  20. (三)微信小程序之发送服务通知(模板消息)

热门文章

  1. mongodb first
  2. 各种id生成策略
  3. Unity 5.1+ Assertion Library (断言库)
  4. django的视图函数介绍
  5. sqlserver2008debug存储过程
  6. 84直方图最大矩形覆盖 &#183; Largest Rectangle in Histogram
  7. MongoDB的数据类型(四)
  8. Java中spring读取配置文件的几种方法
  9. php反射机制学习
  10. TextView UI美化-------自适应字体控件