C. Tennis Championship dp递推 || 找规律
http://codeforces.com/contest/735/problem/C
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 2and 3 he can't play against player 4, as he has 0 games played, while player 1 already played2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
设dp[i]表示比赛了i局,最小需要的人数。
dp[1] = 2;
dp[2] = 3;
dp[3] = 5;
dp[i] = dp[i - 1] + dp[i -2]
这样是最优的。因为dp[i] = val表示最大那个人比赛了i句,需要的最小人数是val,那么比赛了i局的再和比赛了i - 1局的打,打赢它就能产生i + 1局的结果,由于都是最小人数,所以第i + 1局也是最小人数。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e6 + ;
struct node {
LL val;
LL tim;
node(LL A, LL B) : val(A), tim(B) {}
node() {}
bool operator < (const struct node & rhs) const {
return val < rhs.val;
}
}a[maxn];
int lena;
void init() {
a[++lena].val = ;
a[lena].tim = ; a[++lena].val = ;
a[lena].tim = ; a[++lena].val = ;
a[lena].tim = ; a[++lena].val = ;
a[lena].tim = ; a[++lena].val = ;
a[lena].tim = ;
LL pre = ;
LL last = ;
LL to = ;
const LL end = 1e18L;
while (true) {
if (pre + last < ) break;
if (pre + last > end) break;
++lena;
a[lena].val = pre + last;
a[lena].tim = to++;
pre = last;
last = a[lena].val;
// cout << lena << endl;
// cout << a[lena].val << endl;
}
}
void work() {
LL n;
cin >> n;
if (n >= a[lena].val) {
cout << a[lena].tim << endl;
return;
}
int pos = upper_bound(a + , a + + lena, node(n, 0L)) - a;
// cout << pos << endl;
cout << a[pos - ].tim << endl;
// cout << lena << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
init();
work();
return ;
}
C. Tennis Championship dp递推 || 找规律的更多相关文章
- codeforces 735C Tennis Championship(贪心+递推)
Tennis Championship 题目链接:http://codeforces.com/problemset/problem/735/C ——每天在线,欢迎留言谈论. 题目大意: 给你一个 n ...
- MT【103】二阶递推找规律
评:如果直接找$a_n$的二阶递推式:$a_{n+2}-2\sqrt{2}a_{n+1}-a_n=0$有根号,不利于估计尾数.
- codeforces 353D 递推 找规律
题意:一组男生女生在排队,每秒钟所有排在女生左边的男生与她相邻的女生交换位置,求女生全部换到男生前面的时间. 思路: 解法一:队伍最前面的那些女生不需要交换,后面的女生有两种状态:畅通无阻,前一个女生 ...
- LA 3357 (递推 找规律) Pinary
n位不含前导零不含连续1的数共有fib(n)个,fib(n)为斐波那契数列. 所以可以预处理一下fib的前缀和,查找一下第n个数是k位数,然后再递归计算它是第k位数里的多少位. 举个例子,比如说要找第 ...
- 51nod 1350 斐波那契表示(递推+找规律)
传送门 题意 分析 我们发现该数列遵循下列规律: 1 1,2 1,2,2 1,2,2,2,3 1,2,2,2,3,2,3,3 我们令A[i]表示f[i]开始长为f[i-1]的i的最短表示和 那么得到A ...
- UVALive - 6577 Binary Tree 递推+找规律
题目链接: http://acm.hust.edu.cn/vjudge/problem/48421 Binary Tree Time Limit: 3000MS 问题描述 Binary Tree is ...
- hdu2089(数位DP 递推形式)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 2154 跳舞毯 | DP | 递推 | 规律
Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥. 小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是 ...
- "红色病毒"问题 HDU 2065 递推+找循环节
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=2065 递推类题目, 可以考虑用数学方法来做, 但是明显也可以有递推思维来理解. 递推的话基本就是状态 ...
随机推荐
- powerdesigner 导入mysql数据库(步骤及注意点)
参考博客 PowerDesigner中导入MYSQL数据库结构的步骤 mysql ODBC 在64位下提示找不到odbc驱动问题 PowerDesigner逆向工程导入MYSQL数据库总结
- redis的图形界面管理工具
大部分人都知道redis是一款用在缓存服务器上的软件,它与memcache类似,都可以存储海量的数据,用在大访问量的web网站.聊天记录存放等方面,但是又与memcache不同: 1.缓存数据可以持久 ...
- uptime详解,最通俗的说明了cpu平均负载
今天又个网友问uptime的三个平均负载值具体要怎么理解,发现要自己解释还真不知道怎么表达~~~~,下面到网上找了篇文章给大家分享: uptime命令,有两大用处,一个是看您的机器的运行时间,另一 ...
- read appSettings in configuration file by XElement with xmlns
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/how-to-write-queries- ...
- skynet实践(8)-接入websocket
我从开源项目(https://github.com/lipp/lua-websockets,这里我们简称LWS)中抽出了websocket的部分处理,步骤如下: 1)首先是解决LWS的几个依赖问题.L ...
- 「NOIP2000」「Codevs1042」 进制转换
题目描述 Description 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1*102+2 ...
- javascript之存储数据-cookie,localStorage,sessionStorage
cookie: 存储一些简单的数据,以文本形式放到本地,大小4kb 存储:document.cookie='name=value' 取值:document.cookie(字符串) 期限:expires ...
- CSS counter计数器(content目录序号自动递增)详解
一.CSS计数器三角关系 CSS计数器只能跟content属性在一起的时候才有作用,而content属性貌似专门用在before/after伪元素上的.于是,就有了,“计数器↔伪元素↔content属 ...
- hibernate -- 分页模糊查询中setParameter 和setParameterList
在分页模糊查询中碰到setParameter 和setParameterList这两个方法 setParameter 以前就只会用setParameter(int arg,String str),我用 ...
- Hackerrank: Week of Code 36
Cut a Strip 题目简述:给定$n \times m$的矩阵$a[][]$,要求选择一个$x \times 1(1 \leq x \leq k)$的(连续)子矩阵并清零后,找到最大和的(连续) ...