poj 1003 Hangover

简介:

我只能说我又刷了一道水题。。。基本题目理解了,就是注意一下强制转换就可以了。

题目大意:已知c=1/2+1/3+1/4+....1/(n+1).现给出一个值m,求n的值使得c刚好超过m。


AC的代码:


#include <stdio.h>

int main()
{
	double c;
	int i;

	while(scanf("%lf",&c))
	{
		if(c==0)
			return 0;

		for(i=2; ;i++)
		{
			c-=(double)1/i;
			
			if(c<0)
				break;
		}

		printf("%d card(s)\n",i-1);
	}
	
	return 0;
}


相关文章
|
2天前
Hopscotch(POJ-3050)
Hopscotch(POJ-3050)
poj 2299 求逆序数
http://poj.org/problem?id=2299 #include using namespace std; int aa[500010],bb[500010]; long long s=0; void merge(int l,int m,int r) { ...
767 0
|
并行计算 网络架构
poj-1005-l tanink i need a houseboat
Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned ...
939 0
POJ-1003-hangover
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.
737 0
|
机器学习/深度学习 算法
|
机器学习/深度学习

热门文章

最新文章