【17.76%】【codeforces round 382C】Tennis Championship

时间:2022-09-10 21:12:57

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

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

Input

The only line of the input contains a single integer n (2 ≤ n ≤ 1018) — the number of players to participate in the tournament.

Output

Print the maximum number of games in which the winner of the tournament can take part.

Examples

input

2

output

1

input

3

output

2

input

4

output

2

input

10

output

4

Note

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 * the winners.

题目链接:http://codeforces.com/contest/735/problem/C

【题解】



类斐波那契数列,找规律.

列个表;

n ans
2 1
3 2
4 2
5 3
6 3
7 3
8 4
9 4
10 4
11 4
12 4
13 5

n=x的情况可以转化为max(ans(n=a),ans(n=b))+1其中a+b==x;

选择的a和b的ans要为相邻的即abs(ans(a)-ans(b))<=1;

这就相当于两个人都击败了若干个对手,然后再在一起打一场;

比如上面的表;

n=9 = max(ans(n=4),ans(n=5))+1=max(2,3)+1==4;

考虑第一次出现ans=1的位置为n=2;

第一次出现ans=2的位置为n=3;

则第一次出现ans=3的位置为n=5;

且3,4的ans都为2;



n***2 3 4 5

ans 1 2 2 3

考虑第一次出现ans=2的位置为n==3;

第一次出现ans = 3的位置为n==5;

则则第一次出现ans=max(2,3)+1==4的位置为n==8;

且n=5,6,7的时候ans==3;因为6=3+3,7=3+4;



n***2 3 4 5 6 7 8

ans 1 2 2 3 3 3 4

同理

第一次出现ans = 3的位置为n==5;

第一次出现ans =4的位置为n=8;

则第一次出现ans=max(3,4)+1==5的位置为n==13;

且n=8,9,10,11,12时,ans=4;因为8=5+3,9 = 5+4,10=5+5,11=5+6,12=5+7



n***2 3 4 5 6 7 8 9 10 11 12 13

ans 1 2 2 3 3 3 4 4 *4 **4 *4 *5

由此可以写出程序

(注意开LONG LONG)

    cin >> n;
ans[2] = 1;ans[3] = 2;//n<=3的情况直接写出来;
if (n>3)
{
LL a = 2,b = 3,c=a+b;
LL now = 2;
while (c <=n)//如果n大于等于a+b,则表示ans可以再增大
{
a = b;b = c;//a变成now-1第一次出现的位置,b变成now第一次出现的位置
c = a+b;//则c就变成now+1第一次出现的位置了;
now++;//所代表的ans递增;
}
cout << now << end;
}
else
cout << ans[n];

【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second typedef pair<int,int> pii;
typedef pair<LL,LL> pll; void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} //const int MAXN = x;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);
int ans[5];
LL n,now = 0; int main()
{
while (cin>>n)
{
ans[2] = 1;ans[3] = 2;
if (n>3)
{
LL a = 2,b = 3,c=a+b;
now = 2;
while (c <=n)
{
a = b;b = c;
c = a+b;
now++;
}
cout << now << endl;
}
else
cout << ans[n]<<endl;
}
return 0;
}

【17.76%】【codeforces round 382C】Tennis Championship的更多相关文章

  1. 【57&period;97&percnt;】【codeforces Round &num;380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【42&period;86&percnt;】【Codeforces Round &num;380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【26&period;83&percnt;】【Codeforces Round &num;380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【21&period;21&percnt;】【codeforces round 382D】Taxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【50&period;88&percnt;】【Codeforces round 382B】Urbanization

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【Codeforces Round 1137】Codeforces &num;545 &lpar;Div&period; 1&rpar;

    Codeforces Round 1137 这场比赛做了\(A\).\(B\),排名\(376\). 主要是\(A\)题做的时间又长又交了两次\(wa4\)的. 这两次错误的提交是因为我第一开始想的求 ...

  7. 【Codeforces Round 1132】Educational Round 61

    Codeforces Round 1132 这场比赛做了\(A\).\(B\).\(C\).\(F\)四题,排名\(89\). \(A\)题\(wa\)了一次,少考虑了一种情况 \(D\)题最后做出来 ...

  8. 【Codeforces Round 1120】Technocup 2019 Final Round &lpar;Div&period; 1&rpar;

    Codeforces Round 1120 这场比赛做了\(A\).\(C\)两题,排名\(73\). \(A\)题其实过的有点莫名其妙...就是我感觉好像能找到一个反例(现在发现我的算法是对的... ...

  9. 【Codeforces Round 1129】Alex Lopashev Thanks-Round &lpar;Div&period; 1&rpar;

    Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的 ...

随机推荐

  1. WWDC2016 观后杂感

    WWDC2016已经落幕了,我没有熬夜看看的录播. 总的来说觉得还是比较兴奋的,因为苹果将更多的APi开发出来了,可以玩出更多花样了.

  2. 小试ijkplayer编译

    同步发表于 http://avenwu.net/ijkplayer/2015/05/07/hands_on_ijkplayer_preparation 谈到视频播放大家都知道ffmpeg,基于其的衍生 ...

  3. 在Sharepoint 2010中启用Session功能的说明文档

    在Sharepoint 2010中启用Session功能的说明文档 开发环境:Windows 7系统,SharePoint Server 2010,Visual Studio 2010 按以下步骤进行 ...

  4. java对称加密报错&colon;Input length must be multiple of 8 when decrypting with padded cipher

    HTTP Status 500 - Request processing failed; nested exception is javax.crypto.IllegalBlockSizeExcept ...

  5. Andrew Ng机器学习课程笔记--week9&lpar;下&rpar;(推荐系统&amp&semi;协同过滤)

    本周内容较多,故分为上下两篇文章. 本文为下篇. 一.内容概要 1. Anomaly Detection Density Estimation Problem Motivation Gaussian ...

  6. 修改linux 默认SHELL

    首先你得查看可以用的shell: 1.命令:chsh -l ,结果如下: /bin/sh/bin/bash/sbin/nologin/usr/bin/sh/usr/bin/bash/usr/sbin/ ...

  7. BZOJ3926 &lbrack;Zjoi2015&rsqb;诸神眷顾的幻想乡 字符串 SAM

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ3926.html 题目传送门 - BZOJ3926 题意 给定一个有 $n$ 个节点,最多只有 $20$ ...

  8. S 实现精确加减乘除

    //加法函数 function accAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[ ...

  9. AbelSu的区块链笔记

    最近几年,像比特币.以太坊.ICO.区块链等概念突然成为互联网热门话题,今天写这篇博客,也是做一些笔记,大概说一下对这个的解释和其他相关内容. 区块链: 区块链是分布式数据存储.点对点传输.共识机制. ...

  10. VMware 虚拟机CentOS 7 网路连接配置 无eth0简单解决办法

    个人博客:http://www.cnblogs.com/miaojinmin799/ 在前面几步基本和网上linux配置差不多,最后一步要配置eth0时出现如图所示结果使用ifconfig -a命令 ...