菜鸟学习ACM,纪录自己成长过程中的点滴。

学习的路上,与君共勉。

ACM学习-POJ-1003-Hangover

Hangover
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 92150   Accepted: 44638

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)

Source

问题要求:已知c=1/2+1/3+1/4+....1/(n+1).现给出一个值m,求n的值使得c刚好超过m。

问题分析:问题很简单,就是遍历,直到找到满足条件的那个n。 但是要注意运算的时候进行类型转换。(最早做的时候卡在这里了,一时粗心没注意)


下面给出AC代码

#include <stdio.h>

int main()
{
double sum_;
double result_;
int n; while ((~scanf("%lf", &sum_)) && sum_ != 0.00 )
{
result_ = 0.00;
for (n=2;result_ <= sum_ ; n++)
{
result_ += 1.00/(double)n;//注意类型的转换
}
printf("%d card(s)\n", n-2);
}
return 0;
}

ACM学习-POJ-1003-Hangover的更多相关文章

  1. POJ.1003 Hangover ( 水 )

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

  2. OpenJudge / Poj 1003 Hangover

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

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

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

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

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

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

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

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

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

  7. poj 1003 Hangover

    #include <iostream> using namespace std; int main() { double len; while(cin >> len & ...

  8. ACM学习

    转:ACM大量习题题库   ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库.   US ...

  9. ACM学习-POJ-1143-Number Game

    菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1143-Number Game Number Game Time Limit: 1000MS   Memory ...

随机推荐

  1. codecomb 2085【肥得更高】

    题目背景 自2009年以来,A.B站的历史就已经步入了农业变革的黎明期. 在两站的娱乐及音乐区,金坷垃制造业早已得到长足的发展,甚至有些地方还出现了坷垃翻唱的萌芽. 新兴肥料人开始走上历史的舞台. 他 ...

  2. Eight(South Central USA 1998)(八数码) 分类: bfs 2015-07-05 22:34 1人阅读 评论(0) 收藏

    The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've see ...

  3. poj 2395 Out of Hay(最小生成树,水)

    Description The cows have run <= N <= ,) farms (numbered ..N); Bessie starts at Farm . She'll ...

  4. weblogic8.1在myeclipse中启动正常,在单独的weblogic中无法正常启动的解决方案.

    应用程序服务器weblogic8.1.5,项目在myeclipse中启动正常,在单独的服务器中启动就报错了.错误如下图: 经过观察,发现在myeclipse中设置了以下的jar包.估计是这个问题引起的 ...

  5. nomasp 博客导读:Android、UWP、Algorithm、Lisp(找工作中……

    Profile Introduction to Blog 您能看到这篇博客导读是我的荣幸.本博客会持续更新.感谢您的支持.欢迎您的关注与留言.博客有多个专栏,各自是关于 Android应用开发 .Wi ...

  6. 使用java连接hive,并执行hive语句详解

    安装hadoop 和 hive我就不多说了,网上太多文章 自己看去 首先,在机器上打开hiveservice hive --service hiveserver -p 50000 & 打开50 ...

  7. 基于redis AE异步网络架构

    最近的研究已redis源代码,redis高效率是令人钦佩. 在我们的linux那个机器,cpu型号, Intel(R) Pentium(R) CPU G630 @ 2.70GHz  Intel(R) ...

  8. hdu1753()模拟大型实景数字相加

    标题信息: 手动求大的实数在一起, pid=1753">http://acm.hdu.edu.cn/showproblem.php?pid=1753 AC代码: /**  *大实数相加 ...

  9. SSCTF Final PWN

    比赛过去了两个月了,抽出时间,将当时的PWN给总结一下. 和线上塞的题的背景一样,只不过洞不一样了.Checksec一样,发现各种防护措施都开了. 程序模拟了简单的堆的管理,以及cookie的保护机制 ...

  10. 【输入输出挂】【Uva11462】Age Sort

    例题17  年龄排序(Age Sort, UVa 11462)照从小到大的顺序输出. [输入格式] 输入包含多组测试数据.每组数据的第一行为整数n(0<n≤2 000 000),即居民总数:下一 ...