Hangover
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 109231   Accepted: 53249

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)

水题,求 1/2 + 1/3 + 1/4 + ... + 1/(n + 1)>=c的最小n。输出时候注意要将退出的n减2才符合条件。

代码:

#include <iostream>
using namespace std; int main()
{
double x,sum=0;
int n;
cin>>x;
for(;;)
{
if(!x)
break;
for(n=2;;n++)
{
if(sum>x)
break;
sum=sum+(double)1/n;
}
cout<<n-2<<" card(s)"<<endl;
sum=0;
cin>>x;
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1003:Hangover的更多相关文章

  1. 「POJ - 1003」Hangover

    BUPT 2017 summer training (16) #2C 题意 n个卡片可以支撑住的长度是1/2+1/3+1/4+..+1/(n+1)个卡片长度.现在给出需要达到总长度,求最小的n. 题解 ...

  2. OpenJudge / Poj 1003 Hangover

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

  3. POJ.1003 Hangover ( 水 )

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

  4. 牛客网 PAT 算法历年真题 1003: 数素数 (20)

    1003:数素数 (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 令Pi表示第i个素数.现任给两个正整 ...

  5. 题目1003:A+B

    题目1003:A+B 时间限制:1 秒内存限制:32 兆 题目描述: 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开. 现在请计算A+B的结果,并以正常形式 ...

  6. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

  7. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  8. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

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

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

随机推荐

  1. java虚拟机之垃圾回收机制

    一.需要回收的内存区域     程序计数器.虚拟机栈.本地方法栈 3 个区域随线程生灭(因为是线程私有),栈中的栈帧随着方法的进入和退出而有条不紊地执行着出栈和入栈操作.而 Java 堆和方法区则不一 ...

  2. ch5 创建类似按钮的链接

    锚是行内元素,所以只有在单击链接的内容时它们才会激活,如果可以实现为按钮的效果,就可以有更大的可单击区域,实现方法为:display设置为block,修改width.height和其他属性,代码如下: ...

  3. 7.2 Varnish 模式

  4. vb.net导出CSV文件

    Public Function WriteToCSV(ByVal dataTable As DataTable, ByVal filePath As String, ByVal records As ...

  5. leetcode844 Backspace String Compare

    """ Given two strings S and T, return if they are equal when both are typed into empt ...

  6. 图片索引 lire

    1:定义  LIRE( Lucene Image Retrieval)相似图像索引和搜索机制 2:资料来源     LIRE官网:http://www.semanticmetadata.net/lir ...

  7. 第四张5G牌照发给广电,能打破三大运营商的垄断吗?

    近段时间,多个国家处于莫须有的安全性考虑,禁止华为参与核心5G网络设备竞标.其实这就从侧面反映出,国内民族企业在5G层面的领先性.当然,这也让我们认知到,5G网络将是新时代的竞争关键节点.为此,国内正 ...

  8. centos6或7查看端口占用及解除占用

    一.查看端口占用 netstat -lnp|grep 要查看的端口号 例如:查看占用端口7000的进程 netstat -lnp|grep 7000 二.清除占用 (1)一次性的清除占用80端口的程序 ...

  9. 前端 移动端H5页面 DEBUG

    下载网址:https://github.com/Tencent/vConsole 把这个JS复制到项目里面 然后引入到HTML中 然后在JS上面实例化一下即可 页面就会有一个绿色的,然后点击一下就可以 ...

  10. GDOI#345. 送礼物「JSOI 2015」01分数规划+RMQ

    题目描述 JYY和CX的结婚纪念日即将到来,JYY来到萌萌开的礼品店选购纪念礼物.萌萌的礼品店很神奇,所有出售的礼物都按照特定的顺序都排成一列,而且相邻的礼物之间有一种神秘的美感.于是,JYY决定从中 ...