Codeforces Round #382 (Div. 2) Tennis Championship (斐波那契)
来源:互联网 发布:兼职淘宝新媒体编辑 编辑:程序博客网 时间:2024/05/01 22:32
题意:n个人两两PK,赢了留下,输了淘汰,问最后赢的人获胜需要的最大场数
思路:令f[i]为赢i场需要的人数,容易发现是一个斐波那契....然后就做完了
#include<bits/stdc++.h>using namespace std;#define LL long longLL fic[105];void init(){fic[0]=0;fic[1]=1;fic[2]=2;for(int i = 3;i<=88;i++)fic[i]=fic[i-1]+fic[i-2];}int main(){ init(); LL n;scanf("%lld",&n);LL ans = 0;int cnt = 1;n-=2;ans++;while(n>0){ n-=fic[cnt++];if(n>=0)ans++;}printf("%lld\n",ans);}
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.
- Codeforces Round #382 (Div. 2)C. Tennis Championship(递推,斐波那契)
- Codeforces Round #382 (Div. 2) Tennis Championship (斐波那契)
- Codeforces Round #382 (Div. 2) C. Tennis Championship(斐波那契递推)
- Codeforces Round #382 (Div. 2) -- C. Tennis Championship (数学找规律 -- 斐波那契数列)
- 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)-735C. Tennis Championship(递推)
- Codeforces Round #382 (Div. 1) A. Tennis Championship
- Codeforces Round #382 (Div. 1) A. Tennis Championship(递推)
- Codeforces Round #382 (Div. 1) 736A Tennis Championship
- Codeforces Round #382 (Div. 1) A. Tennis Championship
- Codeforces Round #382 (Div. 2) C. Tennis Championship 递推、斐波拉契数列
- Codeforces Round #382 (Div. 2)C. Tennis Championship(贪心) D.巴赫猜想
- 【17.76%】【codeforces round 382C】Tennis Championship
- Codeforces#382(Div. 2) C.Tennis Championship【递推】
- Codeforces Round #382 (Div. 2)A到D题 A. Ostap and //B. Urbanization//C. Tennis Championship//D. Taxes
- sql游标
- oracle to_date日期格式图片在转换整个输入字符串之前结束
- [转] Linux进程状态
- CodeForces 173E
- 使用POI实现报表打印功能
- Codeforces Round #382 (Div. 2) Tennis Championship (斐波那契)
- untiy 优化
- APP推送的实现-----极光推送
- CentOS 6 安装OpenVPN
- java基础
- unable to locate package
- Android 限制EditText只能输入数字、限制输入类型、限制输入长度的小技巧
- Delphi获取Excel文档创建、修改、访问的日期和时间
- Java-互相关联的实体无限递归问题