[POJ1003]Hangover
[POJ1003]Hangover
试题描述
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
输入
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
输出
输入示例
- 1.00
- 3.71
- 0.04
- 5.19
- 0.00
输出示例
- card(s)
- card(s)
- card(s)
- card(s)
数据规模及约定
见“输入”
题解
先预处理一下 S[k] = 1/1 + 1/2 + 1/3 + ... + 1/k 的前缀和,因为输入最多是 5.20,看到样例非常良心,所以应该不会比 273 大多少,我就预处理了前 100 个。
每个询问二分答案就好了。(或者直接扫一遍也能过)
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <stack>
- #include <vector>
- #include <queue>
- #include <cstring>
- #include <string>
- #include <map>
- #include <set>
- using namespace std;
- const int BufferSize = 1 << 16;
- char buffer[BufferSize], *Head, *Tail;
- inline char Getchar() {
- if(Head == Tail) {
- int l = fread(buffer, 1, BufferSize, stdin);
- Tail = (Head = buffer) + l;
- }
- return *Head++;
- }
- int read() {
- int x = 0, f = 1; char c = getchar();
- while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
- while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
- return x * f;
- }
- #define maxn 1010
- double S[maxn];
- int main() {
- for(int i = 1; i <= maxn - 10; i++) S[i] = S[i-1] + 1.0 / (double)(i + 1);
- while(1) {
- double x;
- scanf("%lf", &x);
- if(x == 0.0) break;
- int l = 1, r = 1000;
- while(l < r) {
- int mid = l + r >> 1;
- if(S[mid] < x) l = mid + 1; else r = mid;
- }
- printf("%d card(s)\n", l);
- }
- return 0;
- }
[POJ1003]Hangover的更多相关文章
- 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 ...
- 【POJ1003】Hangover(二分搜索)
直接用库函数二分即可. #include <iostream> #include <cstring> #include <cstdlib> #include < ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- HangOver
HangOver Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- Hangover 分类: POJ 2015-06-11 10:34 12人阅读 评论(0) 收藏
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 108765 Accepted: 53009 Descr ...
- HDU1056 HangOver
HangOver Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descript ...
- [POJ] #1003# Hangover : 浮点数运算
一. 题目 Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 116593 Accepted: 56886 ...
随机推荐
- 你需要管理员权限才能删除文件夹及服务器C盘不及批处理
Windows 7系统,管理员权限设置方法 一.选择文件夹或文件所有者 我们用鼠标右键点击要操作的文件或文件夹 - 属性: 在出现的文件夹属性窗口,我们用鼠标左键点击:安全: 我们用鼠标左键点击:高级 ...
- [BZOJ2659][WC2012]算不出的算式(几何)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2659 分析:很巧的想法,原式的值就是y=q/p x这条直线的下面和左边的点的个数.处理 ...
- AngularJS开发指南7:AngularJS本地化,国际化,以及兼容IE低版本浏览器
AngularJS本地化,国际化 国际化,简写为i18n,指的是使产品快速适应不同语言和文化. 本地化,简称l10n,是指使产品在特定文化和语言市场中可用. 对开发者来说,国际化一个应用意味着将所有的 ...
- json_decode详解
json_decode是php5.2.0之后新增的一个PHP内置函数,其作用是对JSON 格式的字符串进行编码. json_decode的语法规则:json_decode ( string $j ...
- [转]JVM 内存初学 (堆(heap)、栈(stack)和方法区(method) )
这两天看了一下深入浅出JVM这本书,推荐给高级的java程序员去看,对你了解JAVA的底层和运行机制有比较大的帮助.废话不想讲了.入主题: 先了解具体的概念:JAVA的JVM的内存可分为3个区:堆(h ...
- python逐行读写
代码: fileReadObj = open("input.txt") fileWriteObj = open("output.txt", 'w') fileL ...
- BZOJ2121 字符串游戏
Description BX正在进行一个字符串游戏,他手上有一个字符串L,以及其 他一些字符串的集合S,然后他可以进行以下操作:对于一个在集合S中的字符串p,如果p在L中出现,BX就可以选择是否将其删 ...
- You've got to find what you love
你必须找到你爱的东西 You've got to find what you love 史蒂夫乔布斯2005年6月在斯坦福大学毕业典礼上的演讲 I am honored to be with you ...
- javascript-如何判断一个对象为数组
Q:如何判断一个对象是否为数组? A1:判断对象的constructor是否指向Array, 接着判断对应的特殊属性,如length,splice之类.这个很容易冒充. A2:使用instanceof ...
- app工程构成
1)工程配置文件: 2)源代码: 3)资源文件.