每天一道算法_4_Hangover

MicroLogix1400编程(使用RSLogix 500 + RSLinx Classic Lite) MicroLogix1400编程 阅读详情

此系列刚开始两天就被十一假期打断了,去山西玩了几天,今天刚回来,为了弥补一下心里的貌似隐隐作痛的愧疚感,挑了个简单的练练手,权当给自己补上一刀。

今天的题目是 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

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.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Hangover {
	
	public static void main(String args[]){
		List<Float> list = new ArrayList<Float>();
		Scanner scanner = new Scanner(System.in);
		int all = scanner.nextInt();
		while(all > 0){
			list.add(scanner.nextFloat());
			all --;
		}
		for(int i = 0; i < list.size(); i ++){
			float f = list.get(i);
			int count = 1;
			float j=2,sum=0;
			for(; sum + (1/j) < f; j ++){
				count ++;
				sum = sum+ (1/j);
			}
			System.out.println(count + " card(s)");
		}
	}
}


 

输入输出如下:

4 1.00 3.71 0.04 5.19
3 card(s)
61 card(s)
1 card(s)
273 card(s)



由于输入的时候弄了半天没想出合适的用0.00结尾的方法,就用了开头先输入一个整数,表示后面要输入的整数个数,然后依次输入的方法,

相信你能看懂。


 

作者:jason0539

微博:http://weibo.com/2553717707

博客:http://blog.csdn.net/jason0539(转载请说明出处)

 

深入博通PEX89000内部:那颗ARM CPU和Synthetic Mode到底能玩出什么花样? 本文深入解析博通PEX89000系列PCIe交换芯片内置的ARM CPU与Synthetic Mode技术,揭示其在AI计算和数据中心的智能潜能。通过ARM Cortex CPU的实时控制和Synthetic Mode的自治网络功能,PEX89000实现了GPU集群的动态拓扑重组和资源池化,大幅提升AI训练效率。文章还探讨了该技术在软件定义数据平面和弹性AI架构中的创新应用。 阅读详情

相关推荐

Weblogic安装与部署

27.免密登录,在目录Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\servers\AdminServer和Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\servers\Server-TA目录下,新建security\boot.properties文件,13.点击新建按钮,填写服务器名称,服务器监听地址,再点击下一步,最后点击完成。

m0_46259466的博客 6642

杭电1056——HangOver(水题)

Problem 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 perpen

pussy_foot 1546

营销反作弊之 异常行为分析模型(一),附带python代码

通过对用户行为进行深入的分析,识别出与常规模式不符的异常行为,可以有效检测并阻止虚假广告点击、刷单、点击欺诈等欺诈行为。本文将详细探讨营销反欺诈中异常行为分析的方法,介绍如何通过数据采集、清洗、行为建模与异常检测,准确识别潜在的欺诈行为,并提供 Python 实现代码示例。**监督学习 (Supervised Learning):**在标注数据的帮助下,训练机器学习模型使其能预测未知数据的结果。营销反欺诈异常行为分析的整体流程涉及多个环节,确保通过对用户行为的深入分析,及时识别潜在的欺诈行为。

viviwiky的博客 1236

【POJ】1003 Hangover

Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 73705   Accepted: 34947 Description How far can you make a stack of cards overhang a table? If you

Manjushri的知识库 1096

ABAP 大规模数据并行处理实战,六套 Parallel Processing Framework 如何选,性能调优真正该盯住什么

如果今天真的面对那份执行 14 个小时的生产报表,我不会马上把原来的 Loop 改成 50 个aRFC。我会先用 SAT、ST12、SQL Monitor 和 HANA 侧工具确认时间到底花在哪里。如果 90% 时间其实消耗在一条低效 SQL 上,Parallel Processing 只是让 50 个 Worker 同时执行那条低效 SQL,数据库会比原来更痛苦。应该先把串行逻辑本身优化到合理水平。该做 Set-based Processing 的地方先交给 HANA。该避免SELECT。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 164

【UVM实战】第七章:UVM中的寄存器模型(1)寄存器模型简介

寄存器模型简介~

悟已往之不谏 知来者之可追 2085

(POJ 1003)Hangover

HangoverDescriptionHow 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 to

accode的专栏 582

03. 线性规划与混合整数规划 (LP/MIP)

本文介绍了OR-Tools中的线性规划(LP)和混合整数规划(MIP)求解器。主要内容包括:1) LP/MIP的基本概念和数学形式,对比了LP、MIP、ILP和BIP的区别;2) OR-Tools支持的求解器类型,如GLOP、SCIP等,以及它们各自的特点和适用场景;3) 详细展示了如何使用GLOP求解器进行线性规划求解,包括变量定义、约束添加和目标函数设置;4) 介绍了SCIP求解器的配置和使用方法;5) 讨论了变量类型、约束类型、多目标优化等进阶功能。文章通过Java代码示例演示了如何实现一个完整的优化

智慧是做事用的 167

洛谷 SP902:HangOver ← double

●​​​​​​​ 本题浮点数类型要声明为 double,不能是 float。 因为根据样例,若 c=5.19,则 n=273。那么易知 1/(n+1) 将是一个包含很多小数位的数,而 float 精度不够,容易造成截断误差。故需使用 double 型数据。 ● ​​​​​​​杭电 HDUOJ 不支持万能头文件 #include

hnjzsyjyj的专栏 1199

MIPI CPHY学习笔记01:TX物理层一致性测试项解析(LP信令模式)

在手机、平板、智能手表等移动设备中,MIPI C-PHY是负责图像、数据传输的核心接口,它就像设备内部的“高速数据线”,而低功耗(LP)信令模式,是这条“数据线”的“省电模式”,专门用于设备待机、低负载等场景,既要保证信号稳定,又要最大限度降低功耗。物理层一致性测试,就是给这个“省电模式”做的“全面体检”,确保不同厂商的设备能兼容互通。今天,我们就聚焦MIPI C-PHY TX(发射端)的Group 1 LP信令测试,用通俗的语言拆解8个核心测试项,看懂“省电信号”的合格标准。

一只豌豆象的博客 315

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

c语言练习:POJ 1003 宿醉(HangOver)

描述 你能把一叠纸牌悬在桌子上多远?如果您有一张卡,则可以创建最大悬垂的一半卡长度。(我们假设卡片必须垂直于桌子。使用两张牌,您可以使顶部的牌悬垂在底部的半张牌长度上,而底部的牌悬垂在桌子上的三分之一,总最大悬垂为 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)。

m0_63002183的博客 906

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ 1003

POJ 1003 原题 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 pe...

Kingdeguo 1074

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

POJ基础题(一)

1003 hangover 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 perpendicul...

老肥码码码 995

SYU新人提高90题1(基础题)

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

zw1996的博客 1032

周赛反思1

标题:周赛反思 1 题目:D 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 ca

m0_63089316的博客 364

北大OJ1003题

北大OJ1003题 题目 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

qq_40469862的博客 596

zju1045题解

题目:HangOverTime Limit: 1 Second      Memory Limit: 32768 KB 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

neoxuhaotian的专栏 2912

ACM pku 1003 解题报告(练习输入输出)

Hangover Time Limit:1000MS  Memory Limit:10000KTotal Submit:12059 Accepted:4808 DescriptionHow far can you make a stack of cards overhang a table? If you have one card, you can create a maximum ov

Manio 2390

NUC1003 Hangover【数学计算+水题】

Hangover 时间限制: 1000ms 内存限制: 65536KB 问题描述     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 are assum

海岛Blog 895

【HDU 1056】HangOver 题解(分数求和)

问题描述你能把一叠卡片放在桌子上多远?如果你有一张卡,你可以创建一个最大的一半卡长度的外伸。(我们假设卡片必须垂直于桌子。)使用两张卡片,您可以使顶部卡片突出底部一半卡片长度,底部卡片突出桌子三分之一卡片长度,总最大突出长度为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)。如下图所示。

HEX9CF的技术博客 291

【基础编程技巧题】HDOJ1056-HangOver

算法分析 程序代码 #include <stdio.h> int main() { double c; while(scanf("%lf", &c) && c) { int i = 2; double s = 0; while (s<c){ s = s + 1.00 / i; i++; } printf("%d c...

不浪漫宇宙 457

青蛙跳台阶(java)

一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。 刚开始是知道这个是斐波那契数列的变形,可是老想不通这个逻辑,总觉得n级台阶,

dream_one_day的博客 1806
上一篇: android错误之解析包时出现问题(一)
下一篇: 每天一道算法_5_Financial Management
炸斯特
炸斯特 领域专家: 操作系统技术领域 领域专家: 操作系统技术领域
博客等级 码龄15年 8371粉丝 186原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值