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个数的平均值,求这两个平均值的最大和 分析:排个序从后面抽,注意先从末尾抽个数小的,再抽个数大的 ...
随机推荐
- IIS7.5支持html页面包含(include)html页面
前提条件: ServerSideIncludeModule的安装: 在安装iis的时候选择上该服务(“在服务端包含文件”,选项)即可,如下: 1:处理映射程序 添加模块映射 请求路径 *.html 模 ...
- 公网IP映射修改后,原先的图片访问却不行了
描述:www与img在一个公网的nginx下时,www访问img没问题 ip:*.*.*.26 www与jimg同样还在同一组nginx,改另一个公网IP映射进来的时候,却访问不了 ip:*.* ...
- log4net详细配置说明
原文地址:http://blog.sina.com.cn/s/blog_671486bc01011rdj.html 1.概述 log4net是.Net下一个非常优秀的开源日志记录组件.log4net记 ...
- RDBMS,memcache
1.RDBMS即关系数据库管理系统(Relational Database Management System),是将数据组织为相关的行和列的系统,而管理关系数据库的计算机软件就是关系数据库管理系统, ...
- HTTPD服务 openssl的https服务机制
环境: 环境: httpd服务器:10.140.165.169 CA服务器:10.140.165.93 CA服务器配置: 1.安装openssl [root@cnhzdhcp16593 ~]# yum ...
- SQLSERVER 2012之AlwaysOn -- 一次硬件升级引发的问题
这是上周遇到的一个案例:对已有的硬件进行升级而引发的问题,期间还触发了一个比较严重的BUG,可谓多灾多难:不过值得庆幸的是,在一连串连锁问题出现的时候,并没有出现人工操作失误(这往往是在处理故障中风险 ...
- SQLSERVER 2012之AlwaysOn -- 同步模式下的网卡性能优化
本文是基于上一篇<SQLServer 2012之AlwaysOn -- 指定数据同步链路,消除网络抖动导致的提交延迟问题>的问题继续进行优化:具体背景请参照上文: 前后折腾了一个多 ...
- 关于mvc中@Html.DropDownListFor和@Html.DropDownList默认值无法选中问题简单总结
当我们在做类似编辑功能的时候,会给定select选中默认值,然而mvc中偶尔这个功能不能用,或者是强类型的@Html.DropDownListFor不能用.凑巧今天遇到问题,解决问题时发现了mvc的一 ...
- Ember.js系列文章
JS前端框架之Ember.js系列文章 本文为文章索引,主要是罗列Ember.js的相关文章便于阅读. 相关演示代码:github for free. 基础篇 1. EmberJs之What|Why| ...
- Asp.Net Web API 2第十八课——Working with Entity Relations in OData
前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyok/p/3446289.html. 本文的示例代码的下载地址 ...