Codeforces Round #382C. Tennis Championship(递推+斐波那契数列)
来源:互联网 发布:nginx服务启动 编辑:程序博客网 时间:2024/05/23 01:40
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.
Source
Codeforces Round #382 (Div. 2)
My Solution
题意:每个人输了比赛就会被淘汰,每两个人可以打比赛的要求是a赢过x场比赛b赢过y场比赛则当abs(x - y) <= 1 时他们可以进行比赛,总共n个选手,问最终的赢家可能赢过的场次的最大值。
分析:
Let us solve the inverse problem: at least how many competitors should be, if the champion will have n matches. Then there's obvious reccurrent formula: f(n+1)=f(n)+f(n-1) (Let us make the draw in a way, where the champion will play n matches to advance to finals and the runner-up played (n-1) matches to advance the final). So, we have to find the index of maximal fibunacci number which is no more that number in the input.
#include<bits/stdc++.h>using namespace std;long long a[100];int main(){ a[0] = 1;a[1] = 2; for(int i = 2; i <= 90; i++) a[i] = a[i-1] + a[i-2]; long long n; while(cin >> n) { int i = 2; while(n >= a[i]) i++; cout << i - 1 << endl; } return 0;}
- Codeforces Round #382C. Tennis Championship(递推+斐波那契数列)
- Codeforces Round #382 (Div. 2)C. Tennis Championship(递推,斐波那契)
- Codeforces Round #382 (Div. 2) -- C. Tennis Championship (数学找规律 -- 斐波那契数列)
- Codeforces Round #382 (Div. 2) C. Tennis Championship 递推、斐波拉契数列
- Codeforces Round #382 (Div. 2) C. Tennis Championship(斐波那契递推)
- Codeforces Round #382 (Div. 2) Tennis Championship (斐波那契)
- Codeforce 735C Tennis Championship(斐波那契数列)
- Codeforces Round #382 (Div. 2)-735C. Tennis Championship(递推)
- Codeforces Round #382 (Div. 1) A. Tennis Championship(递推)
- codeforce 735 C. Tennis Championship (斐波那契数列||网球比赛)
- CodeForces 735C - Tennis Championship(递推)
- Codeforces#382(Div. 2) C.Tennis Championship【递推】
- 【17.76%】【codeforces round 382C】Tennis Championship
- codeforces 735C Tennis Championship 思维+递推
- Codeforces #382 C Tennis Championship
- Codeforces Round #382 (Div. 2) C - Tennis Championship
- Codeforces Round #382 (Div. 2)C. Tennis Championship(贪心)
- Codeforces Round #382 (Div. 2)-C. Tennis Championship
- Android手势检测GestureDetector
- poj 1852 Ants
- 装饰模式
- Supervisor 守护 dotnetcore 程序
- RxJava的封装和研究
- Codeforces Round #382C. Tennis Championship(递推+斐波那契数列)
- 数据结构与算法分析基础----概念初步&最大子序和四种算法C++实现&对分查找&欧几里德算法
- 自定义Toast
- python获取指定日期范围内的每一天,每个月,每季度
- 解决RecyclerView图片错位
- sql CASE()函数
- Textview增加图片并实现点击与文字设置不同大小颜色
- Gradle常见错误解决
- thinkPHPM 与D方法具有什么区别