Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 101380 | Accepted: 49289 |
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
Output
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
1003 | Accepted | 2976K | 157MS | Java | 549B | 2014-08-16 14:45:13 |
import java.io.BufferedInputStream; import java.util.Scanner; public class Main { static String getNumOfCards(double hangover){ int n = 2; double re = 0.5; while(re < hangover){ re += 1.0/(++n); } return (n-1) + " card(s)"; } public static void main(String[] args) { Scanner in = new Scanner(new BufferedInputStream(System.in)); while(in.hasNext()){ double hangover = Double.valueOf(in.nextLine()); if (hangover == 0.0) break; System.out.println(getNumOfCards(hangover)); } in.close(); } }
相关推荐
【标题】"POJ1003-Hangover"是一个编程竞赛题目,源自北京大学的在线判题系统POJ(Problem Online Judge)。这类题目通常要求参赛者编写程序来解决特定的算法问题,以此锻炼和测试编程技能及算法理解能力。 【描述...
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44187 Accepted: 20574 Description How far can you make a stack of cards overhang a table? If you have one card, you can create a...
POJ 1003题的程序代码,自己写的,很粗糙,但毕竟是第一次做ACM的题,并且AC了……
此外,POJ题目还包括一些数学题目,例如,1001 Exponentiation、1002 487-3279、1003 Hangover 等。这类题目需要程序员使用数学知识和算法来解决问题。 POJ题目是一个非常有价值的资源,对于程序员来说,通过解决...
2. POJ 1003 - 1005: 随着编号的增加,难度逐渐提升,这些题目可能会涉及到更复杂的算法,比如排序、搜索或者递归。学习者需要对算法有基本理解,并能运用到实际问题中。 3. POJ 1014 - 1017: 这部分题目可能涉及到...
* 1003 Hangover * 1701 Dissatisfying Lift * 2301 Beat the Spread! * 2304 Combination Lock * 2328 Guessing Game * 2403 Hay Points * 2406 Power Strings * 2339 Rock, Scissors, Paper * 2350 Above Average ...
【标题】"POJ.rar_poj java_poj1048" 涉及的知识点主要围绕编程竞赛中的“约瑟夫环”问题,这里是一个加强版,使用Java语言进行解决。 【描述】"POJ1048,加强版的约瑟夫问题 难度中等" 提示我们,这个问题是编程...
* 图的深度优先遍历和广度优先遍历:图的深度优先遍历和广度优先遍历是指遍历图的两种方式,如 poj1860、poj3259、poj1062、poj2253、poj1125、poj2240。 * 最短路径算法:最短路径算法是指计算图中两点之间的最短...
【标题】"POJ1159-Palindrome" 是北京大学在线编程平台POJ上的一道编程题目。这道题目主要考察的是字符串处理和回文判断的知识点。 【描述】"北大POJ1159-Palindrome 解题报告+AC代码" 暗示了解决这道问题的方法和...
标题“POJ3253-POJ3253-Fence Repair【STL优先队列】”指的是一个在线编程竞赛题目,源自北京大学的在线判题系统POJ(Problem Online Judge)。该题目要求参赛者使用C++编程语言解决特定的问题,并且在解决方案中...
1. **状态转移方程**:设计复杂的动态规划状态转移方程(poj1191, poj1054, poj3280, poj2029, poj2948, poj1925, poj3034)。 2. **记忆化搜索**:结合动态规划和递归搜索(POJ3254, poj2411, poj1185)。 3. **...
根据给定的文件信息,我们可以总结出一份详细的IT知识训练计划,主要针对编程竞赛和算法学习,特别是聚焦于POJ(Problem Online Judge)平台上的题目训练。这份计划分为两个阶段,初级阶段和中级阶段,共计涉及了165...
【标题】"POJ2002-Squares"是一个经典的计算机编程题目,源自北京大学的在线判题系统(POJ,即PKU Online Judge)。这个题目主要涉及到算法设计和实现,尤其是数学和动态规划方面的知识。 【描述】"解题报告+AC代码...
标题中的"jihe.rar_2289_POJ 3714_poj3714_poj3714 Ra_visual c" 提到了一个压缩文件,可能包含有关编程竞赛或算法解决的资源,特别是与POJ(Problem On Judge)平台上的问题3714相关的。"Ra_visual c"可能指的是...
这些题目是针对ACM竞赛(ACM International Collegiate Programming Contest,简称ICPC)中的编程训练,POJ(Problem Set for Online Judges)是一个在线的编程竞赛平台,提供了许多算法和逻辑思维的练习题目。...
* 较为复杂的动态规划:例如 poj1191、poj1054、poj3280、poj2029、poj2948、poj1925、poj3034。 数学 1. 组合数学: * 加法原理和乘法原理。 * 排列组合。 * 递推关系:例如 poj3252、poj1850、poj1019、poj...
- **例题**:poj1860, poj3259, poj1062, poj2253, poj1125, poj2240 - **解释**:最短路径算法包括Dijkstra算法、Bellman-Ford算法、Floyd算法以及堆优化的Dijkstra算法等。 ##### (3) 最小生成树算法 - **例题**...
- POJ 1003 - How Many Fibs?(斐波那契数列) - POJ 1004 - The 3n + 1 problem(3n+1问题) **相关知识点**: - 排序算法的时间复杂度分析 - 查找算法的空间效率比较 - 数学算法的应用场景及实现方法 ##### 2. ...
3. 1003 Hangover:简单的模拟醉酒状态,注意条件分支。 4. 2301 Beat the Spread!: 模拟体育比赛的赌注,理解概率和比较。 5. 2304 Combination Lock:解锁密码组合,理解排列组合。 6. 2339 Rock, Scissors, Paper...
【标题】"POJ1837-Balance"是一个在线编程竞赛题目,源自著名的编程练习平台POJ(Programming Online Judge)。这个题目旨在测试参赛者的算法设计和实现能力,特别是处理平衡问题的技巧。 【描述】"解题报告+AC代码...