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< ...
随机推荐
- SVN提交.a文件的方法
选择菜单View-->Ignored Files,这样就会显示出ignored的文件,找到你要上传的.a文件,右键“Add”就可以了.
- Java基础之泛型——使用泛型链表类型(TryGenericLinkedList)
控制台程序 定义Point类: public class Point { // Create a point from its coordinates public Point(double xVal ...
- devexpress13学习系列(一)PDFViewer(1)
使用这个组件,可以直接在winform里显示pdf文档,不需要另外装软件了. 有这么几个重要的属性: 1.DocumentFilePath:要读取的PDF的文件和路径. 2.CurrentPageNu ...
- System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
.NET Framework里面提供了三种Timer: System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer VS ...
- 转:MIME(Multipurpose Internet Mail Extensions)类型
MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器 ...
- 转:python webdriver API 之 验证码问题
对于 web 应用来说,大部分的系统在用户登录时都要求用户输入验证码,验证码的类型的很多,有字母数字的,有汉字的,甚至还要用户输入一条算术题的答案的,对于系统来说使用验证码可以有效果的防止采用机器猜测 ...
- 动画--过渡函数 transition-timing-function
transition-timing-function属性指的是过渡的“缓动函数”.主要用来指定浏览器的过渡速度,以及过渡期间的操作进展情况,其中要包括以下几种函数: (单击图片可放大) 案例展示: 在 ...
- Linux内核之旅 链表实现
#include "stdio.h" #include "stdlib.h" struct list_head{ struct list_head *prev; ...
- 1029 C语言文法
program -> external_declaration | program external_declaration <程序> -> <外部声明> ...
- mongodb版本管理
使用gradle. 查找最新版本http://mvnrepository.org/ compile "org.mongeez:mongeez:0.9.6" 配置spring < ...