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 ...
随机推荐
- 解决问题之,wp项目中使用MatchCollection正则表达式匹配出错
在最近,出现了这么一个问题 本人使用正则表达式代码,解析响应output,意图获得周边的CMCC热点 代码如下: //output="<?xml version=\"1.0\ ...
- LeeCode-Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- python爬虫系列之爬京东手机数据
python抓京东手机数据 作者:vpoet mail:vpoet_sir@163.com #coding=utf-8 import urllib2 from lxml import etree im ...
- 修改MySQL 5.5的max_allowed_packet属性的方法
今天在部署一个实验系统的时候,报出下面这个错: Your 'max_allowed_packet' variable is set to less than 16777216 Byte (16MB). ...
- python语言磁力搜索引擎源码公开,基于DHT协议
原文地址: http://www.cnblogs.com/huangxie/p/5550680.html
- IsDbNull 方法的用法
本文来自:http://lazhgg.cnblogs.com/archive/2006/02/21/334915.html 在c#中,进行数据库查询时使用IsDbNull 方法判断数据库中字段值是否存 ...
- 编程获取linux的CPU使用的内存使用情况
Linux可用下top.ps命令检查当前的cpu.mem用法.下面简单的例子: 一.采用ps查看资源消耗的过程 ps -aux 当您查看进程信息,第三列是CPU入住. [root@localhost ...
- PHP学习笔记一
<html> <head> <title></title> <meta http-equiv="content-type" c ...
- iOS控制器的创建方式
iOS控制器的创建.除了常见的alloc init外还有通过加载storyboard和xib的方式,下边逐一展开: 1.代码alloc init 创建方式 ViewController *vc= [[ ...
- [Math]Sqrt(x)
Total Accepted: 75767 Total Submissions: 314003 Difficulty: Medium Implement int sqrt(int x). Comput ...