[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 ...
随机推荐
- 常用API(正则表达式、Date、DateFormat、Calendar)
常用API 今日内容介绍 u 正则表达式 u Date u DateFormat u Calendar 第1章 正则表达式 1.1 正则表达式的概念 正则表达式(英语:Regular Expressi ...
- ZR#330. 【18 提高 3】矿石(容斥)
题意 题目链接 Sol 挺显然的,首先对每个矿排序 那么答案就是$2^x - 2^y$ $x$表示能覆盖到它的区间,$y$表示的是能覆盖到它且覆盖到上一个的区间 第一个可以差分维护 第二个直接vect ...
- Hive基础(1)
Hive基础(1) Hive的HQL(2) 1. Hive并不是分布式的,它独立于机器之外,类似于Hadoop的客户端. 2. 元数据和数据的区别,前者如表名.列名.字段名等. 3. Hive的三种安 ...
- Python+selenium之疑难点解决之去除readonly的限制
去除文本框的readonly只读模式的限制 如图所示:去除卡号readonly限制 代码如图所示: js = 'document.getElementById("cardNo"). ...
- 新手第一天学习 C#语言(进制互换)
说起来我们对一些陌生或者未知的东西有一些恐惧感,但是又有一些期待,虽然我不确定自己能不能学会这门语言,但是我会尽自己最大的努力学. 我们第一天学的的内容呢,对大多数的人都知道,计算机的语言是二进制,但 ...
- VB SMTP用户验证发送mail
转自 http://www.jishuzh.com/program/vb-smtp%E7%94%A8%E6%88%B7%E9%AA%8C%E8%AF%81%E5%8F%91%E9%80%81mail. ...
- Android(java)学习笔记129:对ListView等列表组件中数据进行增、删、改操作
1. ListView介绍 解决大量的相似的数据显示问题 采用了MVC模式: M: model (数据模型) V: view (显示的视图) C: controller 控制器 入门案例: aci ...
- tcp、http和socket的区别
本文原链接:https://www.jianshu.com/p/88d69454bdde tcp.http和socket的区别 一:tcp协议 tcp协议属于传输层协议(UDP也属于传输层协议,但是U ...
- SC || Chapter 5 复习向
可复用性 ┉┉∞ ∞┉┉┉┉∞ ∞┉┉┉∞ ∞┉┉ 行为子结构 对于父子的继承关系的要求: ·子类可以增加方法,但不可以删 ·子类需实现抽象类型中未实现的方法 ·子类重写(override)的方法必须 ...
- PAT (Basic Level) Practise (中文)- 1012. 数字分类 (20)
http://www.patest.cn/contests/pat-b-practise/1012 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数 ...