ACM学习-POJ-1003-Hangover
菜鸟学习ACM,纪录自己成长过程中的点滴。
学习的路上,与君共勉。
ACM学习-POJ-1003-Hangover
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 92150 | Accepted: 44638 |
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
Output
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)
Source
问题要求:已知c=1/2+1/3+1/4+....1/(n+1).现给出一个值m,求n的值使得c刚好超过m。
问题分析:问题很简单,就是遍历,直到找到满足条件的那个n。 但是要注意运算的时候进行类型转换。(最早做的时候卡在这里了,一时粗心没注意)
下面给出AC代码
#include <stdio.h> int main()
{
double sum_;
double result_;
int n; while ((~scanf("%lf", &sum_)) && sum_ != 0.00 )
{
result_ = 0.00;
for (n=2;result_ <= sum_ ; n++)
{
result_ += 1.00/(double)n;//注意类型的转换
}
printf("%d card(s)\n", n-2);
}
return 0;
}
ACM学习-POJ-1003-Hangover的更多相关文章
- POJ.1003 Hangover ( 水 )
POJ.1003 Hangover ( 水 ) 代码总览 #include <cstdio> #include <cstring> #include <algorithm ...
- OpenJudge / Poj 1003 Hangover
链接地址: Poj:http://poj.org/problem?id=1003 OpenJudge:http://bailian.openjudge.cn/practice/1003 题目: Han ...
- [POJ 1003] Hangover C++解题
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95164 Accepted: 46128 De ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- [POJ] #1003# Hangover : 浮点数运算
一. 题目 Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 116593 Accepted: 56886 ...
- 快速切题 poj 1003 hangover 数学观察 难度:0
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103896 Accepted: 50542 Descr ...
- poj 1003 Hangover
#include <iostream> using namespace std; int main() { double len; while(cin >> len & ...
- ACM学习
转:ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. US ...
- ACM学习-POJ-1143-Number Game
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1143-Number Game Number Game Time Limit: 1000MS Memory ...
随机推荐
- Kth Smallest Element in a BST 解答
Question Given a binary search tree, write a function kthSmallest to find the kth smallest element i ...
- UVA 712-S-Trees(满二叉树的简单查询)
题意:给一棵满二叉树,叶子节点赋予权值,0或者1,对于每个查询输出叶子节点的权值,每个查询0代表往左走,1代表往右走,这题坑的地方是层的访问顺序,如第二组测试,由上到下依次是x3,x1,x2,假如给一 ...
- SQL注入原理深度解析
本文转自:http://www.iii-soft.com/forum.php?mod=viewthread&tid=1613&extra=page%3D1 对于Web应用来说,注射式攻 ...
- linux 在批处理中,完整路径有空格的处理方式(加引號)
cp -f E:/XML_EDITOR/xmleditor25/xmleditor/Editor_UIOuterCtrl/TraceViewDlg.cpp E:/XML_EDITOR/'XMLEdit ...
- 【DataStructure】Some useful methods about linkedList(二)
Method 1: Add one list into the other list. For example, if list1is {22, 33, 44, 55} and list2 is { ...
- LoadRunner性能测试中Controller场景创建需注意的几点
在LR工具做性能测试中,最关键的一步是Controller场景的设计,因为场景的设计与测试用例的设计相关联,而测试用例的执行,直接影响最终的测试结果是怎么的,因此,我们每设计一种场景,就有可能是一个测 ...
- Unity 3D 进度条制作
我们都知道玩游戏时,第一步要加载游戏,加载游戏时我们可以做一个简单的进度条来显示游戏加载进度,应为有了进度条,游戏画面不会过于呆板. 那么我们就开始游戏的进度条制作吧! 方法一: 1,使用NGUI制作 ...
- DWZ在APS.NET WebForm中的使用(一)
1.前言 在最近的项目开发中,使用到了前端框架DWZ.DWZ是一款较为优秀的后台管理界面框架,但官方发布的文档确实令人汗颜,简单几页了事,有点对自己的产品不负责任了.同时感谢网友石头的热心帮助,在我这 ...
- BAK文件怎么恢复到数据库中
1.右击SQLServer2000实例下的“数据库”文件夹.就是master等数据库上一级的那个图标.选择“所有任务”,“还原数据库” 2.在“还原为数据库”中填上你希望恢复的数据库名字.这个名字应该 ...
- 谈谈对web标准的理解
Web标准不是某一个标准,而是由一系列标准组合而成.网页主要由三部分组成:结构.表现和行为.对应的标准也分三方面:结构化标准语言主要包括XHTML和HTML以及XML,表现标准语言主要包括CSS,行为 ...