【POJ1003】Hangover(二分搜索)
直接用库函数二分即可。
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <numeric> #define eps 1e-8
using namespace std; double len[]; int main () {
ios :: sync_with_stdio(false);
len[] = ;
for (int i = ; i < ; ++ i) {
len[i] = len[i - ] + 1.0 / (double)(i + );
} //cout << len[273] << endl;
double n;
while (cin >> n) {
if (n - < eps) {
break;
}
//cout << lower_bound(len, len + 300, n) - &len[0] << endl;
printf ("%d card(s)\n", lower_bound(len, len + , n) - &len[]);
}
return ;
}
【POJ1003】Hangover(二分搜索)的更多相关文章
- [POJ1003]Hangover
[POJ1003]Hangover 试题描述 How far can you make a stack of cards overhang a table? If you have one card, ...
- POJ1003 – Hangover (基础)
Hangover Description How far can you make a stack of cards overhang a table? If you have one card, ...
- POJ-1003&1004
这两题比较简单,就不做分析了,描述下题目,就上代码吧. [题目描述] 1003,其实就是求这个方程的最小n:1/2 + 1/3 + 1/4 + ... + 1/(n + 1) >= c: 100 ...
- Hangover[POJ1003]
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 121079 Accepted: 59223 Descr ...
- [LeetCode] Largest BST Subtree 最大的二分搜索子树
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2199:Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 二分搜索 UVALive 6076 Yukari's Birthday (12长春K)
题目传送门 题意:问使得sum (k^i) = n || n -1 (1 <= i <= r) 的min (r*k)组合的r和k 分析:r的最大不会超过40,枚举r,二分搜索k.注意会爆 ...
随机推荐
- 一、mysql分表简单介绍
一.Mysql分表的原因 1.当一张的数据达到几百万时,你查询一次所花的时间会变多,如果有联合查询的话,我想有可能会死在那儿了. 分表的目的就在于此,减小数据库的负担,缩短查询时间. 2.mysql中 ...
- Spring 小示例
通过一个简单的示例来初步理解Spring框架 1.创建java工程,导入相应Spring包,放在lib文件夹中 2.接口 IHelloMessage package com.jike.spring. ...
- java遍历Hashmap/Hashtable的几种方法
一>java遍历Hashtabe: import java.util.Hashtable; import java.util.Set; public class HashTableTest { ...
- tomcat 7配置数据库连接池,使用SQL Server2005实现
昨 天看了一些网上的tomcat数据库连接池配置的东西,但是一直没配好,主要原因是网上的文章几乎没有针对tomcat 7进行配置的,而且针对SQL SERVER的也不多,今天上午看了官方的文档,花了一 ...
- Android + eclipse +ADT安装完全教程
最近几天没事做,网上看来看去突然就想弄个android来学学... 首先,是要下载android SDK,在http://developer.android.com/sdk/index.html这个 ...
- 使用sublime text2怎样新建文件高速生成HTML头部信息?
前提须要安装Emmet插件.安装完毕后重新启动sublime. 输入下面简写,按Tab. html:4t <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ...
- 奔五的人学IOS:swift练手与csdn,最近学习总结
早在五月份就准备開始学习ios开发,当时还是oc,学习了几天,最终不得其法.到了ios8开放,再加swift的出现.从10月份開始.最终找到了一些技巧,学习起来还算略有心得. 今天把我在学习swift ...
- [Cycle.js] Making our toy DOM Driver more flexible
Our previous toy DOM Driver is still primitive. We are only able to sends strings as the textContent ...
- 使用代码自定义UIView注意一二三
文/CoderAO(简书作者)原文链接:http://www.jianshu.com/p/68b383b129f9著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 当一撮样式一样的视图在 ...
- compass模块----Helpers
Color Stops:在使用CSS3渐变属性生成图片的时候,有时候为了打造更丰富的渐变效果除了声明渐变线上的起始点和终止点的色值,还有声明一些中间点的色值,这些点我们就称之为Color Stops. ...