[POJ 1003] Hangover C++解题
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 95164 | Accepted: 46128 |
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
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
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/2 + 1/3 = 5/6 的卡片长度。一般地,如果你有n张卡片,你可以伸出 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) 的卡片长度,也就是最上的一张卡片覆盖第二张1/2,第二张超出第三张1/3,第三张超出第四张1/4,依此类推,最底的一张卡片超出桌面1/(n + 1)。下面有个图形的例子:

现在给定伸出长度C(0.00至5.20之间),输出至少需要多少张卡片。
解决思路
这是一道水题,直接按照要求模拟就可以了。
源码
/*
poj 1000
version:1.0
author:Knight
Email:S.Knight.Work@gmail.com
*/ #include<cstdio>
using namespace std;
int main(void)
{
double c;
int i;
double Overhangs;
while(scanf("%lf", &c) == )
{
if (0.0 == c)
{
return ;
}
Overhangs = ;
for (i=; i; i++)
{
Overhangs += 1.0 / (i + );
if (Overhangs >= c)
{
break;
}
}
printf("%d card(s)\n", i);
}
return ;
}
[POJ 1003] Hangover C++解题的更多相关文章
- POJ.1003 Hangover ( 水 )
POJ.1003 Hangover ( 水 ) 代码总览 #include <cstdio> #include <cstring> #include <algorithm ...
- OpenJudge / Poj 1003 Hangover
链接地址: Poj:http://poj.org/problem?id=1003 OpenJudge:http://bailian.openjudge.cn/practice/1003 题目: Han ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- [POJ] #1003# Hangover : 浮点数运算
一. 题目 Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 116593 Accepted: 56886 ...
- 快速切题 poj 1003 hangover 数学观察 难度:0
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103896 Accepted: 50542 Descr ...
- poj 1003 Hangover
#include <iostream> using namespace std; int main() { double len; while(cin >> len & ...
- POJ 1003 解题报告
1.问题描述: http://poj.org/problem?id=1003 2.解题思路: 最直观的的想法是看能不能够直接求出一个通项式,然后直接算就好了, 但是这样好水的样子,而且也不知道这个通项 ...
- Hangover POJ - 1003
How far can you make a stack of cards overhang a table? If you have one card, you can create a maxim ...
- POJ 1003:Hangover
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 109231 Accepted: 53249 Descr ...
随机推荐
- pc端常见布局---垂直居中布局 单元素定高
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 从SAP客户主数据里直接创建商机(Opportunity)
在SAP CRM Fiori的Account应用里,直接在Account页面创建商机: 在SAP Cloud for Customer里: 要获取更多Jerry的原创文章,请关注公众号"汪子 ...
- SAP GUI里Screen Painter的工作原理
我们在SAP GUI里双击一个screen编号: 单击Layout按钮可以打开Screen Painter: 这背后的工作原理是什么? 是这个RFC destination在起作用: Connecti ...
- C、C++、C#中struct的简单比较
比较这三者是因为C.C++.C#这三者存在着一定的血缘关系,而他们三者都有的struct却有很大的不同. 功能 C中的struct是最简单的.只能有成员变量而不能有成员函数. C++和C#中都支持,而 ...
- Unity3D中使用Projector生成阴影
在Unity3D中使用Projector实现动态阴影 无意中看见一篇博客叙述使用Projector实现动态阴影可以在移动平台拥有非常好的性能,遂按照其想法实现了一遍,发现其中竟有许多细节,写下这篇博客 ...
- Codeforces Round #321 (Div. 2) D Kefa and Dishes(dp)
用spfa,和dp是一样的.转移只和最后一个吃的dish和吃了哪些有关. 把松弛改成变长.因为是DAG,所以一定没环.操作最多有84934656,514ms跑过,实际远远没这么多. 脑补过一下费用流, ...
- python基础一 day14 生成器函数进阶(1)
- appium---常用的adb命令
在测试android-app的时候,adb命令可以帮助我们解决许多问题 什么是adb Android Debug Bridge,我们一般简称为adb,主要存放在sdk安装目录下的platform-to ...
- C08 C语言预处理命令
目录 宏定义 文件包含 条件编译 预处理命令 C语言的预处理:在编译之前进行的处理,不进行编译. C语言的预处理功能有: 宏定义 文件包含 条件编译 预处理命令以符号“#”开头.. 宏定义 不带参数的 ...
- atoi 函数实现
要考虑的东西实在也挺多的.总结如下: 1 前面空格分隔符号的时候 2 第一个符号位处理+ - 3 遇到非数字字符退出 4 为正数的时候,大于INT_MAX上溢 5 为负数的时候 ...