poj日记(1003)
来源:互联网 发布:python怎么往矩阵输入 编辑:程序博客网 时间:2024/05/19 06:15
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.
若将一叠卡片放在一张桌子的边缘,你能放多远?如果你有一张卡片,你最远能达到卡片长度的一半。(我们假定卡片都正放在桌 子上。)如果你有两张卡片,你能使最上的一张卡片覆盖下面那张的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)。下面有个图形的例子:
Input
Output
Sample Input
1.003.710.045.190.00
Sample Output
3 card(s)61 card(s)1 card(s)273 card(s)
import java.util.Scanner; /** * Created by mxc2011 on 2015/1/25. */ public class POJ1003 { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(true) { double m = in.nextDouble(); double sum = 0.0; int i = 1; if (m < 0.00001) { System.exit(0); } if (m <= 0.5) { System.out.println("1 card(s)"); } else { while (sum < m) { i++; sum = sum + 1.0 / i; } System.out.println((i - 1) + " card(s)"); } } } }
- poj日记(1003)
- poj日记(1001)
- poj日记(1753)
- poj日记(1004)
- poj日记(3299)
- poj日记(1005)
- poj日记(1328)
- poj日记(1222)
- poj日记(3295)
- poj日记(1207)
- poj日记(1936)
- poj日记(1860)
- poj日记(2632)
- poj日记(2965)java
- poj日记(2586)java
- poj日记(1017)——贪心算法
- 汉城日记(一)
- 创业日记(转贴)
- Java集合框架之TreeMap的排序
- 【Qt Creator】下载链接
- linus下安装MyCat
- Pytorch
- HDU 1305 Immediate Decodability
- poj日记(1003)
- linux centos下三种配置java环境变量的方法
- Java高级之虚拟机加载机制
- 【转载】CentOS 7 安装 mysql + mysql 常用命令 + docker 运行 mysql
- Python __init__.py 作用详解
- 安卓样式与主题
- 【JavaScript】基本数据类型与引用数据类型区别(及为什么String、Boolean、Number基本数据类型会有属性和方法?)
- java中数组的定义
- 【数据结构】查找算法 Python 版