POJ 1003
2013-05-17 20:03
204 查看
Hangover
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
Sample Output
Source
Mid-Central USA 2001
题目翻译:
你能让一堆卡片悬出桌子多远?如果你有一张卡片,你最多能让它悬出它自身一半的长度(假设卡片对于桌子是垂直的//= =这是为毛。。)。两张卡的话,你就只能悬出在上面那张卡的一半长度,下面那张卡三分之一长度,总的长度就是1/3+1/2=5/6.。。(可以通过计算得出这个结论)。 以此类推的话,你就能得到n张牌能排多长的结论:
1/2 + 1/3 + 1/4 + ...
+ 1/(n + 1) 如图;
输入:包含一组或多组数据。最小0.01最大5.20
输出:对于每一组测试数据,输出达到给出的长度所需的最小卡牌数值。
分析:就是给你个数c,让你求1/2 + 1/3 + 1/4
+ ... + 1/(n + 1) 中大于等于c最小的n值
C++代码:
总结:1、一个就是double的问题了= = int 除法一下子全成0了
2、还有一个是,看大神们的报告全都有打表。。。我还在怀疑自己的程序能不能过时间,没想到过了,但是= =打表是什么!!!!!??
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 88848 | Accepted: 42920 |
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)
Source
Mid-Central USA 2001
题目翻译:
你能让一堆卡片悬出桌子多远?如果你有一张卡片,你最多能让它悬出它自身一半的长度(假设卡片对于桌子是垂直的//= =这是为毛。。)。两张卡的话,你就只能悬出在上面那张卡的一半长度,下面那张卡三分之一长度,总的长度就是1/3+1/2=5/6.。。(可以通过计算得出这个结论)。 以此类推的话,你就能得到n张牌能排多长的结论:
1/2 + 1/3 + 1/4 + ...
+ 1/(n + 1) 如图;
输入:包含一组或多组数据。最小0.01最大5.20
输出:对于每一组测试数据,输出达到给出的长度所需的最小卡牌数值。
分析:就是给你个数c,让你求1/2 + 1/3 + 1/4
+ ... + 1/(n + 1) 中大于等于c最小的n值
C++代码:
#include <iostream> using namespace std; int main() { double c; while(cin>>c) { if(c==0.00) break; double sum=0; double n; for(n=1;;n++) { //double sum=0; sum+=1/(n+1); if(!(sum<c)) { break; } } cout<<n<<" card(s)"<<endl; } }
总结:1、一个就是double的问题了= = int 除法一下子全成0了
2、还有一个是,看大神们的报告全都有打表。。。我还在怀疑自己的程序能不能过时间,没想到过了,但是= =打表是什么!!!!!??
相关文章推荐
- POJ 1050,HDU 1003 最大连续子序列和
- HDU - 1003 - Max Sum && POJ - 1050 - To the Max (经典DP问题)
- POJ 1003 Hangover 悬空
- POJ 1003 Hangover
- poj1003
- POJ1003,POJ1004,POJ1005
- POJ-1003
- POJ 1003 Hangover 水题
- POJ 1003(小数处理?)
- POJ-1003
- POJ 1003 Hangover
- poj 1003 (nyoj 156) Hangover
- POJ 1003 Hangover
- POJ 1003--Hangover
- POJ 1003
- 【POJ】1003 Hangover
- POJ 1003
- poj 1003:Hangover
- poj 1003 水题
- POJ1003题