POJ 1003 Hangover&&NYOJ 156 Hangover【数学题】

计算1+1/2+1/3+++1/n

Hangover

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 104558   Accepted: 50926

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

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.

Output

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.

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

Mid-Central USA 2001

#include<stdio.h>
int main()
{
	double s,sum;
	int i,t;
	while(scanf("%lf",&s),s)
	{
		for(i=2,sum=0;;i++)
		{
			sum+=1.0/i;
			if(sum>=s)
			{
				t=i;
				break;
			}
		}
		printf("%d card(s)\n",t-1);
	}

	return 0;
}
时间: 2024-08-02 11:01:29

POJ 1003 Hangover&&NYOJ 156 Hangover【数学题】的相关文章

poj 1003:Hangover(水题,数学模拟)

Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 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 as

poj 3117 World Cup(简单数学题)

题目链接:http://poj.org/problem?id=3117 World Cup Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8634   Accepted: 4327 Description A World Cup of association football is being held with teams from around the world. The standing is based on

zoj 2358,poj 1775 Sum of Factorials(数学题)

题目poj 题目zoj //我感觉是题目表述不确切,比如他没规定xi能不能重复,比如都用1,那么除了0,都是YES了 //算了,这种题目,百度来的过程,多看看记住就好 //题目意思:判断一个非负整数n能否表示成几个数的阶乘之和 //这里有一个重要结论:n!>(0!+1!+……+(n-1)!), //证明很容易,当i<=n-1时,i!<=(n-1)!,故(0!+1!+……+(n-1)!)<=n*(n-1)!=n!. // 由于题目规定n<=1000000,而10!=362880

搜索学习(1)--POJ 1088滑雪 &amp;&amp; NYOJ 10

题目链接: poj:click here. NYOJ :click here 搜索的经典,记忆化搜索,可以用dp实现, 思路:做了一天了,关键在于记录路径的二维数组和存储图的数组,当前点四个方向都搜一遍,搜了一遍记录被访问了,高度下降才是符合要求,同时最长路径在搜的同时及时更新, 调了好几遍,搜索题目还是发现没能把图抽象化语言去实现,以后要加强,不过发现nyoj能过,同样的代码交到poj就TE了,看了一下测试数据,应该是poj的有点水了,不过数的范围大. 参考代码: #include <cstd

[POJ] #1003# Hangover : 浮点数运算

一. 题目 Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 116593   Accepted: 56886 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. (W

poj 1003 Hangover

#include <iostream> using namespace std; int main() { double len; while(cin >> len && len) { double sum = 0.0; double i = 1.0; int n = 2; while(sum < len) { sum += i/n; ++n; } cout << n-2 << " card(s)" <<

Hangover POJ - 1003

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 overha

[POJ] #1003# 487-3279 : 桶排序/字典树(Trie树)/快速排序

一. 题目 487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 274040   Accepted: 48891 Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or

HDU 1046 &amp; POJ 1450 Gridland【有趣的数学题】

Gridland Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5697    Accepted Submission(s): 2607 Problem Description For years, computer scientists have been trying to find efficient solutions to