这个估计是里面第二简单的了,因为第一简单的是求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. 原创:微信小程序调用【统一下单】、【支付】、【支付回调】api并处理请求

    1.服务器端使用TP3.2处理(随便写在一个Controller里面) /* 小程序报名,生成订单 */ public function make_order(){ if(IS_POST){ $dat ...

  2. MongoDB-开始学习MongoDB(一)

    先来看看MongoDB的优缺点: 优点:简单的扩展.快速的读写.灵活的数据类型 缺点:不支持对SQL的支持.支持的特性不够丰富.现有产品不够成熟 应用场景: 适用场景: 持久化缓存层.实时的高效性(读 ...

  3. Log4Net的概念和使用

    第一篇文本日志 log4net简介: log4net简介: log4net是一个功能著名的开源日志记录组件,由java平台而来. 利用log4net可以方便地将日志信息记录到文件.控制台.Window ...

  4. Python 各种库的安装

    在Win7 系统安装的Python 各种库,如:pandas.numpy.scipy等 因为平时使用的是IDE-PyCharm,这里可以直接 [File-Setting-Project:XXX-“+” ...

  5. 设置当前Activity的屏幕亮度

    设置当前的Activity的屏幕亮度,而不是设置系统的屏幕亮度,退出当前的Activity后恢复系统的亮度. 直接看代码好了 Java代码 WindowManager.LayoutParams lp  ...

  6. jQuery瀑布流无限拖三大利器:masonry+imagesloaded+infinitescroll

    瀑布流已经是几乎过时的技术了,不过对于很多想要快速实现它的朋友而言,却绝非易事,因为即使我们已经有很多现成的代码,却发现在自己的开发环境中无法快速得到自己想要的结果.就像我们现在要介绍的三大利器(ma ...

  7. Linux命令-系统健康命令:top

    查看系统健康命令 top之后,按1键可以看到每一个cpu使用情况 top 默认是3秒刷新一次,q退出

  8. 【ASP.NET Core】EF Core - “影子属性” 深入浅出经典面试题:从浏览器中输入URL到页面加载发生了什么 - Part 1

    [ASP.NET Core]EF Core - “影子属性”   有朋友说老周近来博客更新较慢,确实有些慢,因为有些 bug 要研究,另外就是老周把部分内容转到直播上面,所以写博客的内容减少了一点. ...

  9. 尾递归与Continuation

    怎样在不消除递归的情况下防止栈溢出?(无论如何都要使用递归) 这几天恰好和朋友谈起了递归,忽然发现不少朋友对于“尾递归”的概念比较模糊,网上搜索一番也没有发现讲解地完整详细的资料,于是写了这么一篇文章 ...

  10. html 优化 简谈

    一直想写下SEO中关于HTML优化方面的的文章,总算空出这部分时间来了.其实,HTML优化应该是网站内部优化的重点,每个SEOer都需高度重视.根据本人多年实战经验,一般做过HTML优化的网站上线后, ...