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 ]; ...
随机推荐
- tflearn 实现DNN 全连接
https://github.com/tflearn/tflearn/blob/master/examples/others/recommender_wide_and_deep.py import n ...
- Appuim学习路-Appuim介绍
(学一个东西,总的知道它支持什么.为什么要选择它吧?所以我就去看github上的介绍了.发现大家介绍的来源大多来自于此) Appium是一个开源的自动化框架,是跨平台的,允许所有平台使用同一套AP ...
- linux - 文件拆分
核心: split 例如,把一个文件以10万行为单位拆分文件, 并且以perfix作为前缀,3位数数字,从000开始递增 split -l 100000 filename.txt -d -a 3 pe ...
- PIE结对编程
学习进度条 点滴成就 学习时间 新编写代码行数 博客量 学到知识点 第一周 8 0 0 了解软件工程 第二周 7 0 1 了解软件工程 第三周 11 0 1 用例图 第四周 6 25 0 结对编程 第 ...
- 64位tomcat不能配32位的JDK使用
警告: The APR based Apache Tomcat Native library failed to load. The error reported was [D:\apache-tom ...
- Spring声明式事务管理(基于XML方式实现)
--------------------siwuxie095 Spring 声明式事务管理(基于 XML 方式实现) 以转账为例 ...
- 给乱序的链表排序 · Sort List, 链表重排reorder list LoLn...
链表排序 · Sort List [抄题]: [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: quick ...
- 215. Kth Largest Element in an Array(QuickSort)
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...
- [leetcode]340. Longest Substring with At Most K Distinct Characters至多包含K种字符的最长子串
Given a string, find the length of the longest substring T that contains at most k distinct characte ...
- Tomcat:A cookie header was received[xxxxxx] that contained an invalid cookie. That cookie will be ignored.
搬运来源:https://blogs.yahoo.co.jp/dk521123/36721868.html 原因: *从Tomcat 8,Cookie的解析已经符合RFC 6265. *由于RFC 6 ...