/**
* 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)
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s;
try {
while (!"0.00".equals(s = br.readLine())) {
double d = Double.parseDouble(s);
//仅1张card时长度为2/1,因此以其为第一个底数,递增直到大于需要的长度
double count = 2;
while((d-=1/count)>0){
count ++;
}
System.out.println((int)(count-1)+" card(s)");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
题目大意:说在桌子边上叠卡片能叠多长;只有一张卡片的时候,它可以有1/2的长度伸出来;两张卡片的话,叠在下面的就只能伸出1/3了,上面的那张依旧是露出1/2……
也就是求1/2+1/3+1/4+……1/n的了,上面用的方法嘛
没啥技术含量的,不过结果还是能出来,嘿嘿,我的目标还是accept就行
分享到:
相关推荐
The POSIX 1003.1-2001 standard defines an application programming interface (API) for writing multithreaded applications. This interface is known more commonly as pthreads. A good number of modern ...
北京大学ACM练习网站1003题代码,具体请参考http acm pku edu cn JudgeOnline problem id 10
1003 斐波那契函数 1008 甲/乙 1010 架桥 1011 带我飞到半人马座阿尔法星 1012 有机卷心菜 1037 措施 1075 分配 1094 酒吧 1100 空白 1110 正循环 1152 字数 1157 学习单词 1158 约瑟夫斯问题 1212 八进制二进制 ...
34.5 NP-complete problems 1003 35 Approximation Algorithms 1022 35.l The vertex-cover problem 1024 35.2 The traveling-salesman problem 1027 35.3 The set-covering problem 1033 35.4 Randomization and ...
1003 1004 1006 1007 专题分类 (一)简单搜索 ID Problem C++ Source 1 HDU 2553 (精简版) 2 HDU 1312 3 POJ 3984 4 POJ 2251 5 POJ 3278 6 POJ 3279 7 ZOJ 1002 8 POJ 1321 9 HDU 1241 (二)树 ID Problem C++ Source...
1003 1004 1006 1007 专题分类 (一)简单搜索 ID Problem C++ Source 1 HDU 2553 (精简版) 2 HDU 1312 3 POJ 3984 4 POJ 2251 5 POJ 3278 6 POJ 3279 7 ZOJ 1002 8 POJ 1321 9 HDU 1241 (二)树 ID Problem C++ Source...
ECNU 1-100 部分AC程序 problem list : 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1011 1012 1013 1014 1015 1017 1018 1019 1020 1023 1026 1027 1029 1030 1031 1036 1037 1038 1040 ...
- Changes to correct a BurnInTest crash problem on some systems. When the disk and standard RAM tests are run for many hours, BurnInTest may have disappeared with no error message. Release 5.3 ...
1396 The Umbrella Problem: 2054 简单题 1058 Currency Exchange 简单题 1076 Gene Assembly 简单题 1092 Arbitrage 简单题 1093 Monkey and Banana 简单题 1094 Matrix Chain Multiplication 简单题 ...
1396 The Umbrella Problem: 2054 简单题 1058 Currency Exchange 简单题 1076 Gene Assembly 简单题 1092 Arbitrage 简单题 1093 Monkey and Banana 简单题 1094 Matrix Chain Multiplication 简单题 ...
30.9 EXAMPLES 1003 30.10 TOWARDS A PROOF RULE 1022 30.11 A SUMMARY OF THE MECHANISM 1025 30.12 DISCUSSION 1028 30.13 KEY CONCEPTS INTRODUCED IN THIS CHAPTER 1032 30.14 BIBLIOGRAPHICAL NOTES 1033 ...
The C++ Standard Library A Tutorial and Reference (2nd Edition)+cppstdlib-code.zip C++标准库(第二版)英文版.pdf 非扫描版+源代码 Prefaceto the SecondEdition xxiii Acknowledgments for the Second...