Description

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.



Input

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.

Output

For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.

Sample Input

1.00
3.71
0.04
5.19
0.00

Sample Output

3 card(s)
61 card(s)
1 card(s)
273 card(s)
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
double t[10000];
t[0]=0;
int i=0;
for(;t[i]<=5.2;)
{
i++;
t[i]=t[i-1]+1.00/(i+1);
}
double x;
while(cin>>x&&x)
{
int l, r;
l = 0;
r = i ;
while (l + 1 < r)
{
int mid = (l + r) / 2;
if ((t[mid] - x)<-0.0000001)
l = mid;
else
r = mid;
}
cout << r << " card(s)" << endl; } return 0;
}

E - Hangover(1.4.1)的更多相关文章

  1. poj 1003:Hangover(水题,数学模拟)

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Descri ...

  2. Hangover[POJ1003]

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 121079   Accepted: 59223 Descr ...

  3. [POJ1003]Hangover

    [POJ1003]Hangover 试题描述 How far can you make a stack of cards overhang a table? If you have one card, ...

  4. HangOver

    HangOver Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. Hangover 分类: POJ 2015-06-11 10:34 12人阅读 评论(0) 收藏

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 108765   Accepted: 53009 Descr ...

  6. HDU1056 HangOver

    HangOver Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descript ...

  7. [POJ] #1003# Hangover : 浮点数运算

    一. 题目 Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 116593   Accepted: 56886 ...

  8. OpenJudge / Poj 1003 Hangover

    链接地址: Poj:http://poj.org/problem?id=1003 OpenJudge:http://bailian.openjudge.cn/practice/1003 题目: Han ...

  9. POJ1003 – Hangover (基础)

    Hangover   Description How far can you make a stack of cards overhang a table? If you have one card, ...

  10. 快速切题 poj 1003 hangover 数学观察 难度:0

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103896   Accepted: 50542 Descr ...

随机推荐

  1. hdu 5163(前缀和+分类讨论)

    Taking Bus Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. [BZOJ4989][Usaco2017 Feb]Why Did the Cow Cross the Road 树状数组维护逆序对

    4989: [Usaco2017 Feb]Why Did the Cow Cross the Road Time Limit: 10 Sec  Memory Limit: 256 MBSubmit:  ...

  3. React+React Router+React-Transition-Group实现页面左右滑动+滚动位置记忆

    2018年12月17日更新: 修复在qq浏览器下执行pop跳转时页面错位问题 本文的代码已封装为npm包发布:react-slide-animation-router 在React Router中,想 ...

  4. (21)C#VS快捷键

    1.移动光标 ctrl+ 右键:按单词移动 home:移动到一行得开头 ,end:移动到一行得末尾 ctrl+home:移动到文本得第一行初始位置,ctrl+end文本最末尾 pageDn:往文件下面 ...

  5. 「kuangbin带你飞」专题二十二 区间DP

    layout: post title: 「kuangbin带你飞」专题二十二 区间DP author: "luowentaoaa" catalog: true tags: - ku ...

  6. ELK获取用户真实IP

    原理:在filebeat这台服务器上的nginx中获取到客户端真实IP($clientRealIp),    然后在访问日志中添加"$clientRealIp"字段.1. 通过ma ...

  7. JSK 18: 跳跃游戏

    题目描述 给定一个非负整数数组,假定你的初始位置为数组第一个下标. 数组中的每个元素代表你在那个位置能够跳跃的最大长度. 请确认你是否能够跳跃到数组的最后一个下标. 例如:$A = [2,3,1,1, ...

  8. How to show only next line after the matched one?

    awk '/blah/{getline; print}' logfile

  9. 一种用XAML写Data Converter的方式

    在WPF程序中,数据绑定是非常常用的手段.伴随着数据绑定,我们通常还需要编写一些Converter.而编写Converter是一件非常枯燥的事情,并且大量的converter不容易组织和维护. 今天在 ...

  10. jdk7 cpocurrent ForJoinPool

    19. 使用 ForkJoinPool 进行分叉和合并 ForkJoinPool 在 Java 7 中被引入.它和 ExecutorService 很相似,除了一点不同.ForkJoinPool 让我 ...