这个估计是里面第二简单的了,因为第一简单的是求a+b

哈哈,一submit就ac了

题目如下:

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>
using namespace std; class Overhang {
private:
double a;
public:
int getCardsNum();
void getValue() { cin >> a; }
double geta() { return a; }
}; int Overhang::getCardsNum() {
int num=1;
double sum=0.0;
while(true) {
sum += 1.0/(num+1);
num++;
if (sum >= a)
return --num;
}
}
int main(void) {
Overhang t;
while(true) {
t.getValue();
if ((t.geta() - 0.0) < 0.0001)
return 0;
cout << t.getCardsNum() << " card(s)" << endl;
}
}

pku oj overhang叠加卡片求最少的卡片数的更多相关文章

  1. Counting Kangaroos is Fun 求最少可见袋鼠数

    Description There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaro ...

  2. HDU 1326 Box of Bricks(水~平均高度求最少移动砖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 题目大意: 给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同. 解题思路: 找到 ...

  3. poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】

    Road Construction Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10141   Accepted: 503 ...

  4. 输入一个数字n 如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数 写出一个函数

    题目: 输入一个数字n  如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数  写出一个函数 首先,这道题肯定可以用动态规划来解, n为整数时,n的解为 n/2 的解加1 n为奇数时 ...

  5. PKU OJ 1002 487-3279

    PKU OJ 1002 487-3279 487-3279 Description Businesses like to have memorable telephone numbers. One w ...

  6. [Leetcode 216]求给定和的数集合 Combination Sum III

    [题目] Find all possible combinations of k numbers that add up to a number n, given that only numbers ...

  7. 我的第一篇博客:不用sizeof求int的bit数

    我的第一篇博客..  还不会什么高端的东西就来点基础的. 不用sizeof求int的bit数 //不用sizeof求int的bit数 #include<stdio.h> int main( ...

  8. hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。

    题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...

  9. java笔试之求最大连续bit数

    功能: 求一个byte数字对应的二进制数字中1的最大连续数,例如3的二进制为00000011,最大连续2个1    输入: 一个byte型的数字    输出: 无     返回: 对应的二进制数字中1 ...

随机推荐

  1. 一般web典型的项目目录结构

    本文转自:http://blog.sina.com.cn/s/blog_4758a28b0100l3lp.html WebRoot-       -common   (系统框架公用jsp 如foote ...

  2. HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  3. skimage exposure模块解读

    exposure模块包括: 直方图均衡化 gamma调整.sigmoid调整.log调整 判断图像是否对比度太低 exposure模块包括以下函数: histogram 统计颜色的直方图,基于nump ...

  4. windows批处理文件打印幻方

    无论是批处理文件还是shell都是没有意义的,它们只是一种工具,并且是非常低级难懂的工具. 如果不会,那就保持不会就好了.不要花费太多时间在这些没意义的事情上. 批处理的没意义体现在: 难以表达 随便 ...

  5. ios 中的tintColor

    在iOS 7后,UIView新增加了一个tintColor属性,这个属性定义了一个非默认的着色颜色值,其值的设置会影响到以视图为根视图的整个视图层次结构.它主要是应用到诸如app图标.导航栏.按钮等一 ...

  6. HttpClient 解释

    HttpClient:是一个接口 首先需要先创建一个DefaultHttpClient的实例 HttpClient httpClient=new DefaultHttpClient(); 发送GET请 ...

  7. python学习笔记014——错误和异常

    Python有两种错误很容易辨认:语法错误和异常. 1 什么是语法错误 Python 的语法错误或者称之为解析错,是初学者经常碰到的,如下实例 if i>4 print("if语句输出 ...

  8. C语言sprintf与sscanf函数

    1.前言 我们经常涉及到数字与字符串之间的转换,例如将32位无符号整数的ip地址转换为点分十进制的ip地址字符串,或者反过来.从给定的字符串中提取相关内容,例如给定一个地址:http://www.bo ...

  9. Linux Shell之表达式

    严格来说,shell中没有表达式的概念.Shell本身事实上仅仅是一堆命令的集合.当然也不是胡乱的堆在一起.而是有一定的组织.仅仅是这个组织不那么严谨.所以本文不是要真的总结所谓的表达式,而是把she ...

  10. background-image:url(data:image/gif;base64,XXXX) base64方式将本地图片添加到文档中

    background-image:url(data:image/gif;base64,R0lGODlhCwAMAMZjAElxvlNvtVRxtkp1v0p9wVh7vkqBwl58vml6vml7v ...