`
贝壳水母
  • 浏览: 149200 次
  • 性别: Icon_minigender_1
  • 来自: 广州中低收入人群
社区版块
存档分类
最新评论

Problem1003

    博客分类:
  • POJ
阅读更多
/**
 * 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就行
分享到:
评论

相关推荐

    CSUOJ,264个问题的正确代码

    在Problem1003中,采用了一种常用的图搜索算法——深度优先搜索(DFS)。DFS是一种用于遍历或搜索树或图的算法。它沿着图的边尽可能深地搜索直到遇到目标或者无法前进为止。关键代码如下: ```c void dfs(int x, ...

    acm比赛试题

    Problem 1003 本题的标题是“筛素数”,它是一道数论题目,要求筛选出所有的素数。该题目考察了数论和筛选算法的知识点,需要使用筛选算法来解决问题。 知识点: 1. 数论 2. 筛选算法 3. 素数理论 Problem 1004 ...

    POJ1003-Hangover

    【标题】"POJ1003-Hangover"是一个编程竞赛题目,源自北京大学的在线判题系统POJ(Problem Online Judge)。这类题目通常要求参赛者编写程序来解决特定的算法问题,以此锻炼和测试编程技能及算法理解能力。 【描述...

    pthreads-w32-2-1-0-release.tar.gz

    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 ...

    lrucacheleetcode-Online-Problem-Solving::laptop:在线问题解决存储库:laptop:

    1003 斐波那契函数 1008 甲/乙 1010 架桥 1011 带我飞到半人马座阿尔法星 1012 有机卷心菜 1037 措施 1075 分配 1094 酒吧 1100 空白 1110 正循环 1152 字数 1157 学习单词 1158 约瑟夫斯问题 1212 八进制二进制 ...

    北大POJ题目分类,归纳等等的呢个

    1. **简单题**:如1000A+B、1003 Hangover等,这类题目通常涉及到基本的算术运算、字符串处理或简单的逻辑判断,适合初学者入门练习。 2. **数学问题**:包括1001Exponentiation(指数运算)、1014 Dividing(除法...

    算法导论英文版

    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 ...

    xcm.rar_图形图像处理

    【标题】"xcm.rar_图形图像处理"指的是一个与图形图像处理相关的压缩文件,其中可能...具体到第1003题的细节,可能需要访问提供的链接(http://acm.pku.edu.cn/JudgeOnline/problem/id/10)来获取详细题目描述和要求。

    leetcode中国-ACM-Learning:ACM竞赛中关于算法的代码

    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...

    leetcode中国-Homo-sapiens-ACM-Learning:智人-ACM-学习

    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...

    poj题目分类...

    * 2295 A DP Problem 图论及组合数学 图论及组合数学题目是 POJ 上的一种高级题目,它们通常需要使用高级的数学知识和算法来解决。以下是一些推荐的题目: * 2421 Constructing Roads * 2369 Permutations * 2234...

    ECNU 1-100 部分AC程序

    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 ...

    信息学奥赛一本通(C++版)在线评测系统-答案-1000-1009.docx

    1003:对齐输出 该题目主要测试了格式化输出操作,使用`printf`将三个整数按照指定的格式输出到屏幕上。该题目考察了基本的C++语法和格式化输出操作。 1004:字符三角形 该题目主要测试了循环操作和字符处理,使用`...

    poj 前5题的C 和java代码

    Poj(Problem Online Judge)是一个在线编程竞赛平台,它提供了大量的算法题目供程序员进行训练和挑战。这里的“前5题”指的是poj题库中的最初五道题目,而提供的代码则是针对这些题目的解决方案。 1. **C语言基础*...

    BURNINTEST--硬件检测工具

    - 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 ...

    poj 130题 acm pku

    【标题】"poj 130题 acm pku" 涉及的是ACM(国际大学生程序设计竞赛)中的PKU(北京大学)在线判题系统POJ(Problem Online Judge)的相关题目。ACM/ICPC(International Collegiate Programming Contest)是全球...

    二维不规则图形排料CAD系统的设计.pdf

    对于优化排料问题,也就是二维不规则割料问题(2D Irregular Cutting Stock Problem),属于典型的NP完全问题。它涉及到将一组具有不规则形状的零件合理地放入特定区域中的问题,需要满足零件放置在板材内部、零件...

    北京大学poj题目类型分类

    * 1003 Hangover:这是一个简单的字符串处理题目,要求学习者编写一个程序来处理字符串。 搜索题 搜索题是POJ题目中的一种重要题型,通常涉及搜索算法和图论的应用,如深度优先搜索、广度优先搜索、迪杰斯特拉算法...

    强大的poj分类

    - POJ 1004 - The 3n + 1 problem(3n+1问题) **相关知识点**: - 排序算法的时间复杂度分析 - 查找算法的空间效率比较 - 数学算法的应用场景及实现方法 ##### 2. 数据结构 **简介**:数据结构是计算机存储、...

    腾讯俱乐部ACM训练赛进阶组解题报告.pdf

    Meepo's Problem (题目1001) **题目概述**:本题涉及字符串处理和逻辑判断。题目中提到“父亲关系为1,母亲关系为0”,这意味着我们需要通过给定的父子或母子关系来构建一个二进制字符串。具体来说,当关系是父亲时...

Global site tag (gtag.js) - Google Analytics