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. luogu P4129 [SHOI2006]仙人掌

    题目描述 仙人掌图(cactus)是一种无向连通图,它的每条边最多只能出现在一个简单回路(simple cycle)里面.从直观上说,可以把仙人掌图理解为允许存在回路的树.但是仙人掌图和树之间有个本质 ...

  2. Python—处理Excel表格

    一.使用xlrd和xlwt这两个库来处理excel,即xlrd是读excel的库,xlwt是写excel的库 1.使用 xlrd 读取Excel数据 # -*- coding:utf-8 -*- im ...

  3. @vue-cli的安装及vue项目创建

    1.安装 Node.js & Vue CLI @vue/cli3,是vue-进行搭建的脚手架项目,它本质上是一个全局安装的 npm 包,通过安装它,可以为终端提供 vue 命令,进行vue项目 ...

  4. php 增删改查范例(1)

    主页index.php(含多条件查询): <?php$db = new Mysqli("localhost","root","root" ...

  5. Java核心API需要掌握的程度

    分类: java技术2009-08-29 01:03 213人阅读 评论(0) 收藏 举报 javaapiswingxmlio Java的核心API是非常庞大的,这给开发者来说带来了很大的方便,经常人 ...

  6. 提升Essay写作质量,可从这三个层次入手

    “有针对性”读书对写Essay的产生的帮助是非常大的.由浅显的直接成效,到深度的铺垫积累,阅读一共可分为三个层次: 1读Essay: 2读与写作题材相关的材料: 3多样化阅读. 第一层次:读Essay ...

  7. 十五 JSP开发模式&MVC设计模式

    JSP开发模式: JavaBean + JSP  : 缺点:页面代码过多,不利于维护,JSP页面代码变得臃肿 Servlet + JavaBean + JSP :MVC设计模式 M:model   模 ...

  8. 吴裕雄--天生自然JAVAIO操作学习笔记:内存操作流、管道流与打印流操作

    import java.io.* ; class Send implements Runnable{ // 线程类 private PipedOutputStream pos = null ; // ...

  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:自适应大小的按钮组

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. NO29 用户提权sudo配置文件详解实践--志行为审计

     用户提权sudo配置文件详解实践: 放到visudo里:  验证权限: