贞德 @ 2017-06-27 21:16:21
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
int k,n;
double s=0.0000;
cin>>k;
for(int i=1;i<=100000;i++){
s=s+1.0/i;
if(s>k){
n=i;
break;
}
}
cout<<n;
return 0;
}
by 晏小翔Bill @ 2017-06-27 21:54:41
i应该也是double类型
by 晏小翔Bill @ 2017-06-27 21:57:29
而且最好用while形式
by 晏小翔Bill @ 2017-06-27 21:58:01
参考一下我的代码吧
by 晏小翔Bill @ 2017-06-27 22:00:37
个人认为你的代码有一点点复杂
献丑了:
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
double s=0,i=0;
int k;
cin>>k;
while(s<=k)
{
i++;
s=s+1.0/i;
}
cout<<i;
return 0;
}
by c20191623 @ 2017-07-06 09:12:10
#include<stdio.h>
int main()
{
double s;
int k,i,j;
scanf("%d",&k);
s=0.0;
for(i=1;;i++)
{
s=s+1.0/i;
if(s>k)
{
break;
}
}
printf("%d",i);
return 0;
}
我的还不一样?很吓人啊 OJ上面都过了
by yanghaodong @ 2017-07-06 10:51:16
#include<iostream>
using namespace std;
int main()
{
long double m,n=0;
int i;
cin>>m;
for(i=1;n<=m;i++)
{
n+=1.0/i;
}
cout<<i-1;
return 0;
}
by 鲸与梦之歌 @ 2017-07-06 18:18:53
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
int k;
double sum=1;
using namespace std;
int main()
{
cin>>k;
for(int i=2;i<=100000000;i++)
{
sum+=1.0/i;
if(sum>(k))
{
cout<<i;
return 0;
}
}
return 0;
}
by fletmer @ 2017-07-12 21:12:54
你把那个10000去掉,有可能超时了;改成:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int k,n;
double s=0.0000;
cin>>k;
for(int i=1;;i++){
s=s+1.0/i;
if(s>k){
n=i;
break;
}
}
cout<<n;
return 0;
}
by Afri_Trigger @ 2017-07-13 14:31:34
#include<cstdio>
int main(void){
int k;
scanf("%d",&k);
int i=1;
double sn=1.0;
while(sn<=k){
i++;
sn=1.0/i+sn;
}
printf("%d",i);
return 0;
}