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 递推类题目, 可以考虑用数学方法来做, 但是明显也可以有递推思维来理解. 递推的话基本就是状态 ...
随机推荐
- hadoop报JAVA_HOME is not set暂时解决办法
直接在etc/hadoop/hadoop-env.sh中 export JAVA_HOME=XXX
- Safair css hack
一下方式不会影响chrome浏览器样式 _::-webkit-full-page-media, _:future, :root .class{ /*此处放css样式*/ }
- (C)非局部跳转语句(setjmp和longjmp)
1. 特点 非goto语句在函数内实施跳转,而是在栈上跳过若干调用帧,返回到当前函数调用路径上的某一语句. 头文件包含#include Void longjmp(jmp_buf env,int val ...
- vue文档重读有感
vue 官方文档,每次读都有不一样的感受.项目已经做过一个了,遇到了不少问题,下面总结下这次看到的注意点: 一.指令方面 1. v-once 一次性绑定,只渲染元素和组件一次.随后的重新渲染,元素/ ...
- 织梦DEDE后台定时分时段自动更新发布文章插件
定时审核插件使用说明 一.立信CPA培训注册会计师考试网站 以超级管理员身份登录后台,依次选择[核心]à [定时审核管理],输入定时审核的时间段,如下图所示: 功能说明: 1. 可以设置若干时间段,在 ...
- Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.st.mapper.UserMapper.userBaseMap
mybatis出现此异常,可能是因为 ***Mapper.xml 文件中存在重名对象,一不小心重复启动了mybatis的逆向工程. 以为会覆盖掉以前生成的,没想到是新生成的和之前生成的重复了 解决:把 ...
- hdu 1963 Investment 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963 题目意思:有 本金 money,还有一些股票的种类,第 i 种股票买入需要 value[i] 这 ...
- Oracle备份与恢复:冷备份恢复
模拟数据库数据文件丢失的情况下,通过丢失之前的数据文件物理备份做恢复: 说明:数据文件丢失前一刻的所有归档日志都存在. 环境:oracle10g +rhel5 1.关闭数据库,copy system0 ...
- JS截取与分割字符串常用技巧总结
本文实例讲述了JS截取与分割字符串的常用方法.分享给大家供大家参考,具体如下: JS截取字符串可使用 substring()或者slice() 函数:substring() 定义:substring( ...
- 酷版移动端iframe改变src,重新加载页面问题探究
最近在酷版上我要做一个内嵌别人的网页的在线服务页面,于是必须用到iframe,以前我以为移动端不支持iframe呢,原来这样都可以....(呵呵,长见识了!我还是只菜鸟) 直接入正题,说说我遇到的困难 ...