博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1003 Hangover
阅读量:5043 次
发布时间:2019-06-12

本文共 1662 字,大约阅读时间需要 5 分钟。

时间限制: 
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'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 ncards 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.003.710.045.190.00
样例输出
3 card(s)61 card(s)1 card(s)273 card(s)
 
(1)、源代码:
#include  
<iostream>
using  
namespace  
std;
 
int  
main(){
                
int  
i;
                
double  
length,sum;
                
                
while
(1){
                                cin >> length;
                                sum = 0;
                                
if
(length == 0.00)
                                                
break
;
                                
for
(i = 1; i < 300; i++){
                                                sum += 1.0/(i+1);
                                                
if
(sum >= length){
                                                                cout << i <<  
" card(s)\n"
;
                                                                
break
;
                                                }
                                }
                }
                
return  
0;
}
  
(2)、解题思路:略
(3)、可能出错:略
 

转载于:https://www.cnblogs.com/lydf-2012/archive/2012/05/02/2479688.html

你可能感兴趣的文章
超详细的Guava RateLimiter限流原理解析
查看>>
VueJS ElementUI el-table 的 formatter 和 scope template 不能同时存在
查看>>
Halcon一日一练:图像拼接技术
查看>>
Swift - RotateView
查看>>
iOS设计模式 - 中介者
查看>>
centos jdk 下载
查看>>
HDU 1028 Ignatius and the Princess III(母函数)
查看>>
(转)面向对象最核心的机制——动态绑定(多态)
查看>>
token简单的使用流程。
查看>>
django创建项目流程
查看>>
UIActionSheet 修改字体颜色
查看>>
Vue 框架-01- 入门篇 图文教程
查看>>
Spring注解之@Lazy注解,源码分析和总结
查看>>
多变量微积分笔记24——空间线积分
查看>>
Magento CE使用Redis的配置过程
查看>>
poi操作oracle数据库导出excel文件
查看>>
(转)Intent的基本使用方法总结
查看>>
Mac 下的Chrome 按什么快捷键调出页面调试工具
查看>>
Windows Phone开发(24):启动器与选择器之发送短信
查看>>
JS截取字符串常用方法
查看>>