Java程序练习-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 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.


输入
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.
输出
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.
样例输入
1.00
3.71
0.04
5.19
0.00
样例输出
3 card(s)
61 card(s)
1 card(s)
273 card(s)

参考代码

import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNextFloat()){ float ft = cin.nextFloat(); if(ft == 0.0){ break; } float temp = 0; int n = 1; while(temp <= ft){ temp += 1.0 / (n + 1); n ++; } System.out.println((n - 1)+" card(s)"); } } }


杭州电子科技大学OJ解题报告 这是杭电OJ上某些题的解题报告,后续还有上传很多! 立即下载

相关推荐

c语言国际象棋(easyx图形库)

c语言实现的国际象棋,先放源码,有空再更 所有图形资源均来源于网络,侵删 #include <graphics.h> #include<stdio.h> #include<conio.h> #include<math.h> #include<stdlib.h> #include <time.h> #define HEIGHT 800 #define WIDTH 1100 #define SIZE 100 #define true.

Betelgeuse13的博客 1920

VIJOS-P1312 能量项链 【区间DP--矩阵连乘】

VIJOS 传送门 :1312 状态:每个起点及相乘的个数 转换方程: dp[i][k]=max(dp[i][k],dp[i][j]+dp[i+1+j][k-j-1]+dian[i].a*dian[i+j].b*dian[i+k].b); 代码: #include #include #include using namespace std; struct no

leibniz_zhang的博客 529

AIGC在游戏行业的应用:革新游戏开发与体验

AIGC(人工智能生成内容)技术正在深刻改变游戏行业,从开发到体验全面革新。在游戏开发中,AIGC可用于自动生成关卡、角色和剧情,提升开发效率;在资源制作中,通过AI生成场景、角色模型等,降低成本。

1679

Vijos P1045Kerry 的电缆网络

最小生成树判断是否能够连接。

Starlight 1272

数学不好是原罪——高等数学笔记(汇总版)

这是本人之前考研的高数手写笔记,工科学硕数一考了146(满分150),笔记有一定参考价值,欢迎大家收藏借鉴。

xuuyann 5万+

Python 爬取新浪财经 7x24(1): 下载数据

前言 最近在做一个需要很多财经数据的项目。于是想到可不可以通过爬虫来解决(尝试白嫖)。 提供财经数据的网站有很多个,其中比较靠谱和更新比较及时的应该是新浪7x24 live数据。 http://finance.sina.com.cn/7x24/?tag=0 这个问题有一定的难度,因为这个网页是动态加载的。每一次只会加载部分数据,而只有拉到底部才可以加载新的数据。 于是乎,我们要做的事情是: 下载数据 保存到数据库 本篇介绍如何下载数据。 代码 闲言少叙书归正文,代码的实现如下: import reque

ZJ_11701的博客 2922

P1045 Kerry 的电缆网络(Kruskal+并查集)

 描述 Kerry 是德国的一位电缆商人。因联合国脱贫计划的邀请,他准备负责在土鲁齐亚埃萨亚克斯乌托斯邦建立电缆网络,以满足这个国家的用电需求。当然,现在土鲁齐亚埃萨亚克斯乌托斯邦没有任何电缆。已知土鲁齐亚埃萨亚克斯乌托斯邦一共有n个城镇,已经编号为1到n。其中任意两个城镇可能有一条路,也可能没有。如果两个城镇之间有一条路pi,那么这条路有一个长度si,则Kerry可以在这两个城市之间

i641015077的专栏 1202

CST新手必看:共面波导色散曲线绘制全流程(附参数设置详解)

本文为CST新手提供了绘制共面波导色散曲线的完整流程与参数设置详解。从模型搭建、周期性边界条件设置,到本征模求解器配置和参数扫描技巧,逐步解析关键步骤,并分享后处理与结果验证方法,帮助用户高效完成仿真任务。

j0k1l2m3n的博客 434

POJ——1003(Hangover)问题

程序代码如下: import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub double d; Scanner get=new Scanner(System.in); while(get.hasN...

WU2629409421perfect的博客 473

零信任架构实战:“持续验证+动态授权”全流程解析(附策略引擎联动图)

《零信任实战指南:7图拆解核心流程与行业案例》摘要:本文通过7张架构图系统解析零信任五大核心流程:强身份认证、设备检查、动态授权、持续监控和自动降权。对比金融(重数据审计)与制造业(重物理绑定)的落地差异,指出三大常见误区及解决方案。数据显示,零信任可使安全响应提速60%,泄露成本降低45%。文章提供6个月实施路线图,强调零信任是"智能信任"体系,建议企业分阶段改造,优先保护核心系统。附赠金融/制造行业策略模板及甘特图示例。(149字)

sara_han的博客 794

Go基础:Go语言详细介绍,环境搭建,及第一个程序详解

Go语言是Google开发的开源编程语言,具有高效、简洁、并发性强等特点。文章从Go语言的诞生背景、核心特性及应用领域展开介绍,并详细说明了Windows、Linux和macOS下的环境搭建步骤,包括安装、环境变量配置及测试方法。最后通过“Hello, World!”程序解析Go语言基本语法,并演示了编译发布和跨平台编译功能。全文涵盖了Go语言从入门到实践的完整流程,适合初学者快速上手。

数据知道的博客 6806

Hangover

//一个简单问题:#include "stdafx.h"#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ int Card_Num(float n);    float num; while(cin>>num && (int)(num*1000)!=0) {  cout" card(s)" } return 0;}i

SHark专栏 482

SAP 采购订单入库——移动类型

业务场景:采购入库,实物入库至仓库,然后系统同步过账。MIGO:收货、采购订单。 MVT:101 入库,---库存增加。 MVT:移动类型,就是代表业务场景,(比如入库、发货,成本中心发、工单发、报废、盘赢、盘亏等等) 移动类型 1、正向采购入库:101 2、反向冲销(MIGO)102:与101相反,用于错误操作的反向冲销。参考原凭证,全部进行一...

willieyuan的博客 7787

POJ1003 Hangover

POJ1003 Hangover

长弓smile的博客 298

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

HDOJ 1056 HangOver

HangOver Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7898    Accepted Submission(s): 3242 Problem Description How far can you m

哇咔咔的升级之路~ 605

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

【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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

HDOJ 1056 HangOver

HDACM1056 翻译题…import java.util.Scanner;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { double c

whale blog 256

poj1003 Hangover

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

weixin_34010949的博客 101

ZOJ--1045:HangOver

睡前 水一下 没什么难度 import java.util.Scanner; public class HangOver { public static void main(String[] args) { double a,sum; Scanner s=new Scanner(System.in); while((a=s.nextDouble())!=0){ sum=0

yf224的博客 418

HangOver

HangOver Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10608    Accepted Submission(s): 4521 Problem Description How far can you

不会思考的机器 258

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

qq_43734686的博客 178

「POJ - 1003」Hangover

BUPT 2017 summer training (16) #2C 题意 n个卡片可以支撑住的长度是1/2+1/3+1/4+..+1/(n+1)个卡片长度。现在给出需要达到总长度,求最小的n。 题解 模拟加起来,直到长度不小于给定的总长度。 我也写了个java代码^_^ 代码 import java.util.*; import java.io.*; public class Mai...

dingguayi7025的博客 172

每天一道算法_4_Hangover

此系列刚开始两天就被十一假期打断了,去山西玩了几天,今天刚回来,为了弥补一下心里的貌似隐隐作痛的愧疚感,补上一刀。 今天的题目是 Hangover,如下:   Description How far can you make a stack of cards overhang a table? If you have one card, you can create a max

一个本科小生的奋斗史 2988
上一篇: Oracle学习的经验谈
下一篇: Java程序练习-Financial Management
iteye_2060
博客等级 码龄8年 40粉丝 1原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值