Codeforces 735C:Tennis Championship(数学+贪心)
http://codeforces.com/problemset/problem/735/C
题意:有n个人打锦标赛,淘汰赛制度,即一个人和另一个人打,输的一方出局。问这n个人里面冠军最多能赢多少场,其中一个人和另一个人能打比赛当且仅当这两个人赢的局数相差不超过1。
思路:比赛的时候不会做..直接log2(n)交,果断错了。看题解:因为限制条件两个人能比赛当且仅当他们赢得局数相差不超过1,设F[x]为冠军赢x盘的时候需要的总人数,那么有这样的递推式:F[x] = F[x-1] + F[x-2].(其中x-1的人和x-2的人打一盘,赢的人是x-1,就可以变成x了)。就是斐波那契数列。初始的时候F[1] = 2, F[2] = 3。因为斐波那契递增的很快,在1e18里面数量不多,所以先打出一个表,然后二分查找 n >= F[x] 的x,就是最后的答案了。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int N = ; long long dp[N]; int main() {
long long n;
cin >> n;
dp[] = ; dp[] = ;
int r = ;
for( ; ; r++) {
dp[r] = dp[r-] + dp[r-];
if(dp[r] > 1e18) break;
}
int l = ;
while(l <= r) {
int mid = (l + r) >> ;
if(dp[mid] <= n) l = mid + ;
else r = mid - ;
}
printf("%d\n", r);
return ;
}
Codeforces 735C:Tennis Championship(数学+贪心)的更多相关文章
- codeforces 735C. Tennis Championship(贪心)
题目链接 http://codeforces.com/contest/735/problem/C 题意:给你一个数n表示有几个人比赛问最多能赢几局,要求两个比赛的人得分不能相差超过1即得分为2的只能和 ...
- codeforces 735C Tennis Championship(贪心+递推)
Tennis Championship 题目链接:http://codeforces.com/problemset/problem/735/C ——每天在线,欢迎留言谈论. 题目大意: 给你一个 n ...
- Educational Codeforces Round 20 C 数学/贪心/构造
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划
C. Tennis Championship 题目链接 http://codeforces.com/contest/735/problem/C 题面 Famous Brazil city Rio de ...
- Codeforces Round #382 (Div. 2) C. Tennis Championship 斐波那契
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #382 (Div. 2) C. Tennis Championship
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- C. Tennis Championship dp递推 || 找规律
http://codeforces.com/contest/735/problem/C C. Tennis Championship time limit per test 2 seconds mem ...
- Tennis Championship
Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces735C Tennis Championship 2016-12-13 12:06 77人阅读 评论(0) 收藏
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
随机推荐
- 一台电脑多个文件夹安装多个Redis服务
思路: 在弄Mongodb的时候,可以在不同的文件夹下面运行不同的mongodb实例 那么Redis可以吗 现在添加一个Redis文件夹,里面放置redis,修改配置端口为6378 将以前的那个Red ...
- dojo使用笔记: 自定义ConfirmDialog
前言: dojo1.10已经有了原生的ConfirmDialog 做gui应用开发,肯定要用到"确认"对话框, 无论是winForm, swing,还是web,也不管理你用什么技术 ...
- 超炫的3D HTML源代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- sdutoj 2607 Mountain Subsequences
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607 Mountain Subsequence ...
- 浅谈thinkphp中将字符串转换成json数组的方法
这是一部分代码: $client = M("Client");$data = $client->where('user_id ='.$user_id)->select( ...
- Missing artifact com.sun:tools:jar 1.5.0 终极解决方法
在使用m2eclipse插件时,在pom.xml中添加struts2-core.jar包后,需要依赖java运行时的tools.jar进行依赖.但是,此时eclipse无法读取tools包,出现如下错 ...
- Java编程思想(一):大杂烩
在java中一切都被视为对象.尽管一切都是对象,但是操纵的标识符实际上是对象的一个引用,可以将引用想象成是遥控器(引用)来操纵电视机(对象).没有电视机,遥控器也可以单独存在,即引用可以独立存在,并不 ...
- php 迭代器
迭代器(Iterator)模式,又叫做游标(Cursor)模式.GOF给出的定义为:提供一种方法访问一个容器(container)对象中各个元素,而又不需暴露该对象的内部细节. 百度百科: http: ...
- html随笔
<!DOCTYPE HTML> <html> <head> <meta charset = "utf-8"> <script ...
- Spring容器中的Bean
一,配置合作者的Bean Bean设置的属性值是容器中的另一个Bean实力,使用<ref.../>元素,可制定一个bean属性,该属性用于指定容器中其他Bean实例的id属性 <be ...