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 ]; ...
随机推荐
- Word 2003-在一个方框里打勾或打叉
最近有个同事问我,如何在Word中输出一个方框中打勾的符号?查了一下帮助,其实很简单,特记录如下,供碰到的朋友参考: 一.在方框中打勾的方法: 先输入一个大写字母R,然后将R选中,将字体改为“Wind ...
- one by one 项目 part 4
出现异常”The last packet sent successfully to the server was 0 milliseconds ago.“的大部分原因是由于数据库回收了连接,而系统的缓 ...
- 解决:Invalid character found in method name. HTTP method names must be tokens
阿里云上弄了一个tomcat,经常半夜发送崩溃,查看日志发现这个东西,查阅资料发现是Tomcat的header缓冲区大小不够,只需要在server.xml中增加maxHttpHeaderSize字 ...
- Autopilot Pattern Redis
https://github.com/autopilotpattern/redis Architecture 正在运行的群集包括以下组件: Redis :我们使用的是Redis 3.2. Redis ...
- jps command not found已解决
根据当前版本安装devel 包 eg: yum install java--openjdk-devel -y jdk小工具jps介绍 jps(Java Virtual Machine Process ...
- ubuntu中vim的设置
问题:刚安装的VIM中,backspace不能删除字符,且上下左右箭头没反应. 解决方法: sudo vi /etc/vim/vimrc.tiny 修改 set compatible为set noc ...
- css字体加粗
参考 https://zhidao.baidu.com/question/2138403197991538308.html font-weight:bold;
- java线程状态及转换
java线程有6种状态: 新建线程new,启动线程runnable,阻塞block,限时等待timed_waiting,等待线程waiting,终止线程terminated 1.限时等待timed w ...
- ecplice中去掉提示信息的步骤
Window-->preferences-->Java-->Editor-->Hovers-->将Combined Hover前面的对勾去掉-->ok.
- 201621123008 《Java程序设计》第六周实验总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 2. 书面作业 1. clone方法 1.1 在 ...