http://codeforces.com/contest/735/problem/C

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 2and 3 he can't play against player 4, as he has 0 games played, while player 1 already played2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.

设dp[i]表示比赛了i局,最小需要的人数。

dp[1] = 2;

dp[2] = 3;

dp[3] = 5;

dp[i] = dp[i - 1] + dp[i -2]

这样是最优的。因为dp[i] = val表示最大那个人比赛了i句,需要的最小人数是val,那么比赛了i局的再和比赛了i - 1局的打,打赢它就能产生i + 1局的结果,由于都是最小人数,所以第i + 1局也是最小人数。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e6 + ;
struct node {
LL val;
LL tim;
node(LL A, LL B) : val(A), tim(B) {}
node() {}
bool operator < (const struct node & rhs) const {
return val < rhs.val;
}
}a[maxn];
int lena;
void init() {
a[++lena].val = ;
a[lena].tim = ; a[++lena].val = ;
a[lena].tim = ; a[++lena].val = ;
a[lena].tim = ; a[++lena].val = ;
a[lena].tim = ; a[++lena].val = ;
a[lena].tim = ;
LL pre = ;
LL last = ;
LL to = ;
const LL end = 1e18L;
while (true) {
if (pre + last < ) break;
if (pre + last > end) break;
++lena;
a[lena].val = pre + last;
a[lena].tim = to++;
pre = last;
last = a[lena].val;
// cout << lena << endl;
// cout << a[lena].val << endl;
}
}
void work() {
LL n;
cin >> n;
if (n >= a[lena].val) {
cout << a[lena].tim << endl;
return;
}
int pos = upper_bound(a + , a + + lena, node(n, 0L)) - a;
// cout << pos << endl;
cout << a[pos - ].tim << endl;
// cout << lena << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
init();
work();
return ;
}

C. Tennis Championship dp递推 || 找规律的更多相关文章

  1. codeforces 735C Tennis Championship(贪心+递推)

    Tennis Championship 题目链接:http://codeforces.com/problemset/problem/735/C ——每天在线,欢迎留言谈论. 题目大意: 给你一个 n ...

  2. MT【103】二阶递推找规律

    评:如果直接找$a_n$的二阶递推式:$a_{n+2}-2\sqrt{2}a_{n+1}-a_n=0$有根号,不利于估计尾数.

  3. codeforces 353D 递推 找规律

    题意:一组男生女生在排队,每秒钟所有排在女生左边的男生与她相邻的女生交换位置,求女生全部换到男生前面的时间. 思路: 解法一:队伍最前面的那些女生不需要交换,后面的女生有两种状态:畅通无阻,前一个女生 ...

  4. LA 3357 (递推 找规律) Pinary

    n位不含前导零不含连续1的数共有fib(n)个,fib(n)为斐波那契数列. 所以可以预处理一下fib的前缀和,查找一下第n个数是k位数,然后再递归计算它是第k位数里的多少位. 举个例子,比如说要找第 ...

  5. 51nod 1350 斐波那契表示(递推+找规律)

    传送门 题意 分析 我们发现该数列遵循下列规律: 1 1,2 1,2,2 1,2,2,2,3 1,2,2,2,3,2,3,3 我们令A[i]表示f[i]开始长为f[i-1]的i的最短表示和 那么得到A ...

  6. UVALive - 6577 Binary Tree 递推+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48421 Binary Tree Time Limit: 3000MS 问题描述 Binary Tree is ...

  7. hdu2089(数位DP 递推形式)

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. HDU 2154 跳舞毯 | DP | 递推 | 规律

    Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥. 小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是 ...

  9. "红色病毒"问题 HDU 2065 递推+找循环节

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=2065 递推类题目, 可以考虑用数学方法来做, 但是明显也可以有递推思维来理解. 递推的话基本就是状态 ...

随机推荐

  1. 20170228 METHOD handle_data_changed-

    CALL METHOD er_data_changed->add_protocol_entry   METHOD handle_data_changed. DATA: ls_modi TYPE  ...

  2. 20170218 OO-ALV标准工具栏按钮

    原文地址:OO ALV 工具栏对于的功能码   图标与对应的 功能码 明细 &DETAIL 检查 &CHECK 刷新 &REFRESH 剪切 &LOCAL&CU ...

  3. WinDbg调试高内存的.Net进程Dump

    WinDbg的学习路径,艰难曲折,多次研究进展不多,今日有所进展,记录下来. 微软官方帮助文档非常全面:https://msdn.microsoft.com/zh-cn/library/windows ...

  4. MYSQL进阶学习笔记二:MySQL存储过程和局部变量!(视频序号:进阶_4-6)

    知识点三:MySQL存储过程和局部变量(4,5,6) 存储过程的创建:     创建存储过程的步骤: 首先选中数据库 改变分隔符,不让分号作为执行结束的标记.(通常情况下,改变分隔符命令 DELIMI ...

  5. Eos的Wasm智能合约的局限性

    官方只支持用C++写智能合约 用C++写智能合约门槛过高,会把许多开发者挡在门外,C++的复杂性也会让智能合约的设计变得困难. Wasm智能合约的效率并不是最优 由于C++最终也是编译成wasm字节码 ...

  6. NSString -- UILabel中字体有多种颜色,字符串自动计算高度/换行

    一:UILabel中字体有多种颜色 UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(, , , ); label.b ...

  7. SDOI2016 Round1 题解

    BZOJ4513 储能表 数位DP,f[i][2][2][2]表示前i位,是否卡n的上界,是否卡m的上界,是否卡k的下界,枚举每一维的下一位直接转移. #include<cstdio> # ...

  8. Ski Course Design

    链接 分析:读题!读题!读题!重要的事说三遍,中文翻译漏掉了一个重要的地方,每个只能用一次,调了一下午还以为标程错了,其实就是找一段长为17的区间,然后使所有都处于这个区间中代价最小,暴力枚举即可. ...

  9. P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team

    题目描述 After Farmer Don took up Frisbee, Farmer John wanted to join in the fun. He wants to form a Fri ...

  10. [转]Python+Selenium之expected_conditions:各种判断(上)

    原文地址: https://www.jianshu.com/p/f3189f1951cc 其他类似文章: https://www.cnblogs.com/yuuwee/p/6635652.html h ...