今天打多校集训惨爆了,自己果然太水,废了半天劲的题最后是用贪心,明天再写今天的题,今天先写几个水题。。
题意:
把一堆卡片尽可能的伸出桌面,原则是对于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;
}