pku oj overhang叠加卡片求最少的卡片数
这个估计是里面第二简单的了,因为第一简单的是求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叠加卡片求最少的卡片数的更多相关文章
- Counting Kangaroos is Fun 求最少可见袋鼠数
Description There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaro ...
- HDU 1326 Box of Bricks(水~平均高度求最少移动砖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 题目大意: 给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同. 解题思路: 找到 ...
- poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10141 Accepted: 503 ...
- 输入一个数字n 如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数 写出一个函数
题目: 输入一个数字n 如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数 写出一个函数 首先,这道题肯定可以用动态规划来解, n为整数时,n的解为 n/2 的解加1 n为奇数时 ...
- PKU OJ 1002 487-3279
PKU OJ 1002 487-3279 487-3279 Description Businesses like to have memorable telephone numbers. One w ...
- [Leetcode 216]求给定和的数集合 Combination Sum III
[题目] Find all possible combinations of k numbers that add up to a number n, given that only numbers ...
- 我的第一篇博客:不用sizeof求int的bit数
我的第一篇博客.. 还不会什么高端的东西就来点基础的. 不用sizeof求int的bit数 //不用sizeof求int的bit数 #include<stdio.h> int main( ...
- hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...
- java笔试之求最大连续bit数
功能: 求一个byte数字对应的二进制数字中1的最大连续数,例如3的二进制为00000011,最大连续2个1 输入: 一个byte型的数字 输出: 无 返回: 对应的二进制数字中1 ...
随机推荐
- PHP-Ajax跨域解决方案
1.先了解下Ajax跨域问题: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "ht ...
- HDUOJ---3743Frosh Week(BIT+离散化)
Frosh Week Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Android Developers:使ListView滑动流畅
流畅滑动ListView的关键是保持应用程序的主线程(UI线程)从免于繁重处理.确保你的任何硬盘访问,网络访问或者SQL访问在一个单独的线程中.为了测试你的应用个程序的状态,你能启动StrictMod ...
- RabbitMQ消息队列(三):任务分发机制[转]
在上篇文章中,我们解决了从发送端(Producer)向接收端(Consumer)发送“Hello World”的问题.在实际的应用场景中,这是远远不够的.从本篇文章开始,我们将结合更加实际的应用场景来 ...
- C# 调节图片亮度
原文地址:https://www.cnblogs.com/wjr408/p/6727118.html 昨天去客户那里测试,需求才开始,所以很简单,就是测一下能不能接受到视频或图片,然后保存下来,现场客 ...
- 西邮Linux兴趣小组纳新笔试试题
下面是西邮Linux小组今年纳新的笔试试题 1. 下面这个程序的输出结果是什么? int main() { int a = (1, 2); printf(“a = %d\n”, a); return ...
- Linux进程概述
一.介绍 当linux系统中的一个进程运行起来的时候,总是要访问系统的资源,访问文件或者向其他的进程发送信号.系统是否允许其进行这些操作?系统是根据什么来判断该进程的权限?这些问题是和进程信任状(pr ...
- django官方文档学习-入门part3创建用户视图
一.官方的约定: 1.在django中有一个约定.那就是每一个app自己的模板最好放在自己app目录下的templates子目录下. 但是这个还没有完成.最好还是在templates目录下加一个app ...
- cocos2dx当节点存在缩放时要注意的问题
cocos2dx(所有引擎也均如此),如果一个节点存在缩放,一定不要忘了其局部空间里的单位长度也会发生变化.其子节点位移,局部空间转世界空间结果等都会受影响. 有时候我们想将父节点的缩放转移到子节点中 ...
- Netty(六):Netty中的连接管理(心跳机制和定时断线重连)
何为心跳 顾名思义, 所谓心跳, 即在TCP长连接中, 客户端和服务器之间定期发送的一种特殊的数据包, 通知对方自己还在线, 以确保 TCP 连接的有效性. 为什么需要心跳 因为网络的不可靠性, 有可 ...