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

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) 题意:求sum(1/n)=给定数的n
思路:因为n只有可能300种,预处理比较即可,精度0.01,不需要设置eps
#include <iostream>
double tc;
double sum[300];
using namespace std;
int main(){
ios::sync_with_stdio(false);
double s=0;
for(int i=0;i<300;i++){
s+=1.00/(i+2);
sum[i]=s;
}
while(cin>>tc&&tc){
int i=0;
for(int i=0;i<300;i++){
if(sum[i]>=tc){
cout<<i+1<<" card(s)"<<endl;
break;
}
}
if(i==300)cout<<"ERROR"<<endl;
}
return 0;
}

  

快速切题 poj 1003 hangover 数学观察 难度:0的更多相关文章

  1. 快速切题CF 158B taxi 构造 && 82A double cola 数学观察 难度:0

    实在太冷了今天 taxi :错误原因1 忽略了 1 1 1 1 和 1 2 1 这种情况,直接认为最多两组一车了 2 语句顺序错 double cola: 忘了减去n的序号1,即n-- B. Taxi ...

  2. POJ.1003 Hangover ( 水 )

    POJ.1003 Hangover ( 水 ) 代码总览 #include <cstdio> #include <cstring> #include <algorithm ...

  3. 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0

    Help Me with the Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3510   Accepted:  ...

  4. 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0

    Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2806   Accepted:  ...

  5. 快速切题 poj 1002 487-3279 按规则处理 模拟 难度:0

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 247781   Accepted: 44015 Descr ...

  6. 快速切题 poj 3026 Borg Maze 最小生成树+bfs prim算法 难度:0

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8905   Accepted: 2969 Descrip ...

  7. 快速切题 poj 2485 Highways prim算法+堆 不完全优化 难度:0

    Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23033   Accepted: 10612 Descri ...

  8. OpenJudge / Poj 1003 Hangover

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

  9. [POJ 1003] Hangover C++解题

        Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95164   Accepted: 46128 De ...

随机推荐

  1. hdu6127 Hard challenge

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6127 题目: Hard challenge Time Limit: 4000/2000 MS ...

  2. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures

    题目:Problem D. Clones and TreasuresInput file: standard inputOutput file: standard outputTime limit: ...

  3. git服务器-------》用户免密git操作

    找到/etc/ssh/sshd_config文件 开启 RSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile      .ss ...

  4. 20145324 《Java程序设计》第8周学习总结

    20145324 <Java程序设计>第8周学习总结 教材学习内容总结 第十四章 1.NIO使用频道来衔接数据节点,可以设定缓冲区容量,在缓冲区中对感兴趣的数据区块进行标记,提供clear ...

  5. 2017阿里C++研发工程师-校招-单词匹配

    题目描述 给一个字符串, 然后给一个字典. 把字符串分解成字典里的单词组成的句子, 请输出所需空格最少的方案.并输出该方案. 样例 例如: 字符串为: str="ilikealibaba&q ...

  6. Seccon2017-pwn500-video_player

    感觉这个题目并不值500分,有些地方比较牵强,漏洞也比较明显,解题方法有多种,出题者把堆的布局随机化了,不过使用fastbin doublefree的话,可以完全忽视被打乱的堆. from pwn i ...

  7. 二叉树的层次遍历(Java代码实现)

    与树的前中后序遍历的DFS思想不同,层次遍历用到的是BFS思想.一般DFS用递归去实现(也可以用栈实现),BFS需要用队列去实现. 层次遍历的步骤是: 1.对于不为空的结点,先把该结点加入到队列中 2 ...

  8. shell小脚本--网速监控

    在windows中,我们可以在360等管家软件中显示网速,在linux下想要查看实时的网速怎么办呢?当然在linux下也有很多优秀的软件可以实时显示网络状况!但是在这里我们使用shell脚本来先完成网 ...

  9. uboot下ext4ls的用法

    列出sd卡的第一个分区里/bin目录下的内容,示例如下: ext4ls mmc 0:1 /bin

  10. windows组策略屏蔽

    点“IP安全策略,在本地机器”——>创建IP安全策略---->下一步---->名称随便写,如输入阻止,然后一直点下一步,出现提示点是,一直到完成,这个时候就创建了一个名为“阻止”的策 ...