POJ_1003 Hangover

今天打多校集训惨爆了,自己果然太水,废了半天劲的题最后是用贪心,明天再写今天的题,今天先写几个水题。。



题意:

把一堆卡片尽可能的伸出桌面,原则是对于n张卡片,最上面的可以相对它下面那张伸出1/2卡长,第二张可以相对它下面那张伸出1/3卡长。。。最后一张可以相对桌面伸出1/(n+1)卡长,给一个实数r,求最少多少张卡片能够使得伸出桌面的长度达到或超过r倍的卡长?




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)


这题本来就水,但是我写代码没有一遍过,把预处理结果都输出来才发现了错误,最终还是自己打代码少了,竟然用1除以整数。。。。。。。。。。。

以后多刷题,别这么水了。。。。。。。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
#define mxn 10000010
double x;
double sum[mxn];
int main(){
	sum[0]=0;
	for(int i=1;;++i){
		sum[i]=sum[i-1]+1/(double)(i+1);
		//cout<<"i: "<<i<<"sum: "<<sum[i]<<endl;
		if(sum[i]>5.2)	break;
	}
	int ans;
	while(scanf("%lf",&x)!=EOF){
		if(fabs(x)<0.001)	break;
		for(int i=0;;++i)
			if(sum[i]>=x){
				ans=i;
				break;
			}
		printf("%d card(s)\n",ans);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值