Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划
C. Tennis Championship
题目链接
http://codeforces.com/contest/735/problem/C
题面
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
题意
有n个人参加比赛,输了就淘汰,赢了就留下来,最后留下来的是胜利者。
每个人只会和胜利场次和自己绝对值不超过1的人比赛。
问你最多比赛多少场
题解
dp[i]表示比赛i场最多需要多少个人。
那么显然dp[i] = dp[i-1] + dp[i-2]
其实就是fib数列,扫一遍就好了
代码
#include<bits/stdc++.h>
using namespace std;
long long n;
long long ans = 0;
int main()
{
scanf("%lld",&n);
long long a=2,b=1,c;
while(1){
if(a>n)break;
ans++;
c=a;
a=a+b;
b=c;
}
cout<<ans<<endl;
}
Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划的更多相关文章
- Codeforces Round #382 (Div. 2) C. Tennis Championship 斐波那契
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #382 (Div. 2) C. Tennis Championship
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- Codeforces Round #382 (Div. 2) 继续python作死 含树形DP
A - Ostap and Grasshopper zz题能不能跳到 每次只能跳K步 不能跳到# 问能不能T-G 随便跳跳就可以了 第一次居然跳越界0.0 傻子哦 WA1 n,k = map ...
- Codeforces Round #382 (Div. 2) (模拟|数学)
题目链接: A:Ostap and Grasshopper B:Urbanization C:Tennis Championship D:Taxes 分析:这场第一二题模拟,三四题数学题 A. 直接模 ...
- Codeforces Round #382 (Div. 2) D. Taxes 哥德巴赫猜想
D. Taxes 题目链接 http://codeforces.com/contest/735/problem/D 题面 Mr. Funt now lives in a country with a ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces Round #283 (Div. 2) D. Tennis Game(模拟)
D. Tennis Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #382(div 2)
A.= = B. 题意:给出n个数和n1和n2,从n个数中分别选出n1,n2个数来,得到n1个数和n2个数的平均值,求这两个平均值的最大和 分析:排个序从后面抽,注意先从末尾抽个数小的,再抽个数大的 ...
随机推荐
- windows下关闭80端口被system占用的情况
用管理员运行cmd然后用net stop http 停止pid 为4的进程
- 利用SET STATISTICS IO和SET STATISTICS TIME 优化SQL Server查询性能
首先需要说明的是这篇文章的内容并不是如何调节SQL Server查询性能的(有关这方面的内容能写一本书),而是如何在SQL Server查询性能的调节中利用SET STATISTICS IO和SET ...
- 【08_238】Product of Array Except Self
Product of Array Except Self Total Accepted: 26470 Total Submissions: 66930 Difficulty: Medium Given ...
- 1.3 Content Provider
ContentProvider向我们提供了我们在应用程序之间共享数据的一种机制,分为系统的和自定义的,系统的也就是例如联系人,图片等数据. 使用方式:一个应用实现ContentProvider来提供内 ...
- Android--UI
1.layout_width 属性和 layout_height 属性:Android中所有的控件都包含这两个属性,有三种可选值 match_parent, fill_parent, wrap_con ...
- MySQL中distinct和group by性能比较[转]
MySQL中distinct和group by性能比较[转] 之前看了网上的一些测试,感觉不是很准确,今天亲自测试了一番.得出了结论(仅在个人计算机上测试,可能不全面,仅供参考) 测试过程: 准备一张 ...
- linux下解决端口被占用问题
查找被占用的端口: netstat -tln netstat -tln | grep 8080 查看端口属于哪个程序 lsof -i :8080 杀掉占用端口的进程: kill -9 进程ID ...
- livequery源码解读
从使用说起: 若干年前,有一天发现,通过js代码创建的html元素及ajax加载的html,无法被$([selector]).click(function(){...})绑定上事件,于是发现了jQue ...
- solr与.net系列课程(三)solr连接数据库
solr与.net系列课程(三)solr连接数据库 上一章直接讲述的配置文件把大部分人看的很迷惑,大家都想听的是solr到底是怎么用的,好,这一节我们就开始链接数据库,首先讲一下连接之前都要配置哪些 ...
- Java和C#中的接口对比(有你不知道的东西)
1.与Java不同,C#中的接口不能包含字段(Field). 在java中,接口中可以包含字段,但是这些字段隐式地是static和final的.而C#不允许接口中有字段,编译器在编译时就会提示错误(如 ...