poj 1003 Hangover
2014-04-14 20:31
387 查看
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 to the table.) With two cards you can make the top card overhang thebottom 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 overhangsthe table by 1/(n + 1). This is illustrated in the figure below.InputThe 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 least0.01 and at most 5.20; c will contain exactly three digits.OutputFor 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
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 98093 | Accepted: 47542 |
1.003.710.045.190.00Sample Output
3 card(s)61 card(s)1 card(s)273 card(s)
#include<iostream>#include<cstdio>using namespace std;int main(){double len,s;int i,k;while(cin>>len,len){s=0;for(i=2;i<=1000;i++){//cout<<s<<" ";if(s>=len)break;else{s=s+1.0/i;k=i;}}printf("%d card(s)\n",k-1);}}
相关文章推荐
- ubuntu安装goldendict翻译工具,很好用!
- poj 1003 Hangover
- 我为什么放弃Go语言
- CategoryHelper 缓存级下拉框多级联动
- 把Go程序变小的办法
- windows下安装django提示“UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position”
- Lucky Goddess
- Google Code Jam 2014 Qualification 题解
- Go 语言开发工具 LiteIDE x22 发布
- 谷歌新项目Project Tango:用3D成像技术改变人们的交互方式
- 如何在django查看一个group里的所有user
- 每天进步一点点——ubuntu 13.10中安装google的gtest库
- Go语言中接口组合(接口中包含接口)
- [文献阅读] Decoding Algorithm in Statistical Machine Translation
- [杂谈] 部分常用的algorithm及numeric函数
- [算法浅析] Algorithm中Heap用法小结
- 如何下载MOS上的goldengate补丁
- pycharm django
- Chrome&GoAgent访问facebook&YouTube等
- Let's go!