Codeforces735C Tennis Championship 2016-12-13 12:06 77人阅读 评论(0) 收藏
2 seconds
256 megabytes
standard input
standard output
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.
————————————————————————————————————————————————————————————
题目的意思是n个人进行比赛,输了直接淘汰,而每个人只能和赢的场数和自己不超过1的人打,问最后比赛最多次的人比赛了几场?
我们可以清楚 如果一个人要赢k场,那么他必须先赢k-1场,同时在打败一个赢了k-2场的人,所以我们可以清楚地发现这是一个斐波那契数列
所以我们先打表,然后找到小于等于n的是第几位就好了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; int main()
{
long long n;
long long int a[91];
a[0]=0;
a[1]=2;
a[2]=3;
for(int i=3;i<=90;i++)
a[i]=a[i-1]+a[i-2];
while(~scanf("%I64d",&n))
{
int cnt=lower_bound(a,a+90,n)-a;
cnt--;
for(int i=1;i<=90;i++)
if(n==a[i])
cnt++;
cout<<cnt<<endl;
}
return 0;
}
Codeforces735C Tennis Championship 2016-12-13 12:06 77人阅读 评论(0) 收藏的更多相关文章
- 好用到没朋友的大数模板(c++) 2014-10-01 15:06 116人阅读 评论(0) 收藏
#include <iostream> #include <cstring> using namespace std; #define DIGIT 4 //四位隔开,即万进制 ...
- H - Solve this interesting problem 分类: 比赛 2015-07-29 21:06 15人阅读 评论(0) 收藏
Have you learned something about segment tree? If not, don't worry, I will explain it for you. Segm ...
- 浅谈IOS8之size class 分类: ios技术 2015-02-05 19:06 62人阅读 评论(0) 收藏
文章目录 1. 简介 2. 实验 3. 实战 3.1. 修改 Constraints 3.2. 安装和卸载 Constraints 3.3. 安装和卸载 View 3.4. 其他 4. 后话 以前和安 ...
- NPOI 通用导出数据到Excel 分类: C# Helper 2014-11-04 16:06 246人阅读 评论(0) 收藏
应用场景: 在项目中,经常遇到将数据库数据导出到Excel,针对这种情况做了个程序封装.工作原理:利用NPOI将SQL语句查询出的DataTable数据导出到Excel,所见即所得. 程序界面: ...
- A simple problem 分类: 哈希 HDU 2015-08-06 08:06 1人阅读 评论(0) 收藏
A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- {A} + {B} 分类: HDU 2015-07-11 18:06 6人阅读 评论(0) 收藏
{A} + {B} Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- Catch That Cow 分类: POJ 2015-06-29 19:06 10人阅读 评论(0) 收藏
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 58072 Accepted: 18061 ...
- NYOJ-214 单调递增子序列(二) AC 分类: NYOJ 2014-01-31 08:06 233人阅读 评论(0) 收藏
#include<stdio.h> #include<string.h> int len, n, i, j; int d[100005], a[100005]; int bin ...
- Shell脚本编程入门(一) 分类: 学习笔记 linux ubuntu 2015-07-09 21:06 29人阅读 评论(0) 收藏
最近在学shell,记录一下. if语句的使用: 1.判断两个参数大小 #!/bin/sh #a test about if statement a=10 b=20 if [ $a -eq $b ]; ...
随机推荐
- 趣味编程:FizzBuzz(Kotlin版)
fun toFizzBuzzIf(n: Int) = if (n % 3 == 0 && n % 5 == 0) "FizzBuzz" else if (n % 3 ...
- 分类模型评估之ROC-AUC曲线和PRC曲线
http://blog.csdn.net/pipisorry/article/details/51788927 在样本分布及其不均匀的情况下,建议用PRC...可以看下这个精确率.召回率.F1 值.R ...
- EasyUI查询
<script type="text/javascript"> <!-- js --> function search_xxx() { var search ...
- 真验货客户尾缀sql
'; --select * from TB_ADDBOMWG_LOG; --SELECT * FROM TB_MAN_ROUTING_QM; SELECT * FROM IN_ITEM WHERE I ...
- hdoj1003 DP
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- C/C++ 宏
0. #define MALLOC(n, type) \ ( (type *) malloc((n)* sizeof(type))) 1. 宏可以像函数一样被定义,例如: #define min ...
- Asp.net实现同页面内多图片自动上传并带预览显示
FileUpload控件实现单按钮图片自动上传并带预览显示 1.实现原理: 此方法适合针对有后台生成的图片相关内容,例如购物网站商品展示页面中的封面图片,图片的数量由后台访问数据库,并加载到页面.这种 ...
- JAVA 系统变量之System.getenv()和System.getProperty() 用法
Java提供了System类的静态方法getenv()和getProperty()用于返回系统相关的变量与属性,getenv方法返回的变量大多于系统相关,getProperty方法返回的变量大多与ja ...
- vmware14中安装centos7并使用docker发布spring-boot项目
1.vmare中centos7安装(同一路由器无线网络下) 1.1选择桥接模式 1.2修改配置文件 vi /etc/sysconfig/network-scripts/ifcfg-ens33(这里不一 ...
- phpcms如何给已有的模块添加新功能?
phpcms如何给已有的模块添加新功能? 方法一:直接在模块里的控制器文件中添加功能. 不建议使用此方法,因为一旦phpcms升级,有可能会覆盖模块中的文件, 导致你添加的功能丢失. 方法二:新建一个 ...