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 动态规划的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  4. Codeforces Round #382 (Div. 2) 继续python作死 含树形DP

    A - Ostap and Grasshopper zz题能不能跳到  每次只能跳K步 不能跳到# 问能不能T-G  随便跳跳就可以了  第一次居然跳越界0.0  傻子哦  WA1 n,k = map ...

  5. Codeforces Round #382 (Div. 2) (模拟|数学)

    题目链接: A:Ostap and Grasshopper B:Urbanization C:Tennis Championship D:Taxes 分析:这场第一二题模拟,三四题数学题 A. 直接模 ...

  6. 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 ...

  7. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  8. 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 ...

  9. Codeforces Round #382(div 2)

    A.= = B. 题意:给出n个数和n1和n2,从n个数中分别选出n1,n2个数来,得到n1个数和n2个数的平均值,求这两个平均值的最大和 分析:排个序从后面抽,注意先从末尾抽个数小的,再抽个数大的 ...

随机推荐

  1. [f]JQ cookie插件

    jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { options = option ...

  2. HDU1695 GCD(莫比乌斯反演)

    传送门 看了1个多小时,终于懂了一点了 题目大意:给n,m,k.求gcd(x,y) = k(1<=x<=n, 1<=y<=m)的个数 思路:令F(i)表示i|gcd(x,y)的 ...

  3. selenium通过WebDriverWait实现ajax测试,实现等页面元素加载完成

    WebDriverWait(driver, 10)10秒内每隔500毫秒扫描1次页面变化,当出现指定的元素后结束. http://fox1984.iteye.com/blog/1225265new W ...

  4. 跟我学STL系列(1)——STL入门介绍

    一.引言 最近这段时间一直都在自学C++,所以这里总结下自己这段时间的学习过程,通过这种方式来巩固自己学到的内容和以备后面复习所用,另外,希望这系列文章可以帮助到其他自学C++的朋友们. 由于本人之前 ...

  5. Mathematica修改默认字体

    1. 打开Option Inspector 2. 第一个下拉框选择Global Preference, 搜索stylehints 3. 修改字体为想要换的字体FamilyName, 比如换成苹果黑体 ...

  6. atitit.团队建设总结fx O622

    团队建设总结fx O622 大的title 2 建设团队文化 2 办公环境(3s+树+湖) 3 每人一个办公室 3 弹性工作制 3 重大的决定公投体制 3 每年一个kid经验日 3 做自己想到做的事. ...

  7. paip.判断字符是否中文与以及判读是否是汉字uapi python java php

    paip.判断字符是否中文与以及判读是否是汉字uapi python java php   ##判断中文的原理 注意: 中文与汉字CJKV 的区别..日本,韩国,新加坡,古越南等国家也用汉字,但不是中 ...

  8. 使用Maven编译项目遇到——“maven编码gbk的不可映射字符”解决办法 ——转载

    一.问题描述 今天在MyEclipse中使用Maven编译项目源代码时,结果如下了如下的错误

  9. hdu1879 继续畅通工程

    http://acm.hdu.edu.cn/showproblem.php?pid=1879 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

  10. 内存中 OLTP - 常见的工作负荷模式和迁移注意事项(二)

    ----------------------------我是分割线------------------------------- 本文翻译自微软白皮书<In-Memory OLTP – Comm ...