271 条题解
-
-1fan672867217 LV 6 @ 2018-03-19 14:55:24
Java版
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int k=scan.nextInt();
double a=0;
int n=0;
a:for(double i=1.0;;i++)
{
a+=1/i;
if(a>k)
{
n=(int) i;
break a;
}
}
System.out.println(n);
}
} -
-12018-02-07 20:51:01@
#include<iostream>
using namespace std;
int main(){
int a[11],i,k=0,x=0,g;
for(i=0;i<12;i++)
cin>>a[i];
i=0;
while(i<12){
k=300-a[i]+k;
if(k>100){
g=k%100;
x=x+k-g;
k=g;}
if(k<0){
x=-i-1;
break;}
i++;
}
if(x>0){
x=x*1+0.2*x;
cout<<x;
}
else
cout<<x;
} -
-12017-12-02 16:19:13@
用高精度就对啦。。。
#include <stdio.h>
int main()
{
long int n=0,k;double s=0;
scanf("%ld",&k);
while(s<=k)
{
n++;
s+=1/(float)n;
}
printf("%ld",n);
return 0;
} -
-12017-10-31 15:57:32@
#include "iostream" #include "cstdio" using namespace std; double res = 0; int k,cnt; int main() { scanf("%d",&k); while(res <= k) cnt++,res+=1.0/cnt; cout<<cnt<<endl; return 0; }
-
-12017-10-18 11:09:40@
#include<iostream> using namespace std; //int main() //{ // int k; // cin>>k; // unsigned long long n=0; // double s=0; // do{ // s+=1.0/++n; // }while(s<=k); // cout<<n; // return 0; //} //1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 //2 4 11 31 83 227 616 1674 4550 12367 33617 91380 248397 675214 1835421 int main() { int n,a[16]={0,2,4,11,31,83,227,616,1674,4550,12367,33617,91380,248397,675214,1835421}; cin>>n; cout<<a[n]; return 0; }
-
-12017-10-14 11:00:09@
var i,j,k:integer; sum:real; n:longint; begin read(k);n:=0; sum:=0; while (sum<=k) do begin n:=n+1; sum:=sum+1/n; end; write(n); end.
pacal 一遍AC
难度为3的水题2333
是数据太弱了吧 -
-12017-10-03 07:59:27@
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<fstream>
using namespace std;
double k,n,i=1;
int main()
{
//freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
cin>>k;
while(n<=k)
{
n+=1/i;
i++;
}
i--;
cout<<i;
return 0;
} -
-12017-10-03 07:59:06@
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<fstream>
using namespace std;
double k,n,i=1;
int main()
{
//freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
cin>>k;
while(n<=k)
{
n+=1/i;
i++;
}
i--;
cout<<i;
return 0;
} -
-12017-10-02 20:04:30@
#include <iostream>
using namespace std;
int main(){
int num=0;
double sum=0.0,ans=1.0;
cin>>num;
while(sum<=num)
{
sum=sum+(1/ans);
ans++;
}
cout<<ans-1;
} -
-12017-10-02 08:52:59@
补上一年前的题解
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double sn,n,k;
int main()
{
cin>>k;
n=0;sn=0;
while(sn<k)
{
n++;
sn=sn+1/n;
}
cout<<n;
return 0;
}
顶楼上是我一年前的感慨,这代码也是一年前的 -
-12017-09-23 20:51:55@
#include<iostream>
#include<string>using namespace std;
int main()
{
int k;
double s=0.0,i=1.0;
cin >> k;
while(1)
{
s += 1.0 / i;
if (s > k)
{
cout << i << endl;
break;
}
else
i++;
}
return 0;
} -
-12017-08-19 21:31:29@
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <cstdlib>
using namespace std;
int k,n;
double sn=0.00;
int main() {
cin>>k;
sn=0.00;
for(n=1; sn<=k; n++) {
sn+=(double)(1/(double)n);
//cout<<sn<<endl;
}
cout<<n-1<<endl;
return 0;
} -
-12017-08-17 11:26:03@
import re import sys def readln(): return map(int, input().split()) def read(): s = input() k = [] r = [] k = re.split(' ',s) for i in k: r.append(int(i)) return r a = int(input()) stp = 0 i = 0 while i<=a: stp+=1 i+=1/stp print(stp)
-
-12017-08-16 00:39:25@
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> using namespace std; int main(){ double all=0,i; int k; scanf("%d",&k); for(i=1.0;all<=k;i++) { all=all+1.0/i; } printf("%.0lf",i-1); return 0; }
-
-12017-08-09 06:34:17@
真的,最水的一道noip,n开始的时候开小了,觉得1000就行了,
然后5题就AC2个
加3个零ac了33个,就一直往上加#include <iostream>
using namespace std;
int main()
{
int k;
double s=0.0,n;
cin>>k;
for(n=1;n<=10000000;n++)
{
s=s+1.0/n;
if(s>k){
cout<<n;
break;}
}
} -
-12017-07-22 17:17:21@
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
int n;
double Sn,k;
scanf("%lf",&k);
n=1;
Sn=0;
while(Sn<=k)
{
Sn+=1.0/n;
n++;
}
printf("%d",n-1);
return 0;
} -
-12017-07-04 17:41:57@
水题——级数求和
实际上,考虑到这一题的k值如此之小,我们可以通过直接穷举的方法来得出结果:
穷举
{
Sn=
判断Sn是否***大于***k(是:输出;不是:继续穷举)
}
大家喜闻乐见的代码:#include<bits/stdc++.h> using namespace std; int main() { int k,i; double sum; cin>>k; sum=0; for (i=1;i<=1000000;i++) { sum=sum+(1.0/i); if (sum>k) { cout<<i; break; } } return 0; }
-
-12017-06-23 21:36:07@
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
int a,b,n=0,k;
double sum=0.0,i=0.0;
scanf("%d",&k);
while(sum<=k)
{
i=i+1.0;
sum=sum+1.0/i;
n++;
}
printf("%d",n);
} -
-12017-06-18 11:25:03@
C++:
#include <cstdio> #include <iostream> using namespace std; int main(){ int k; scanf("%d", &k); double sum = 0, div = 1; while (sum <= k){ sum += 1.0 / div; div++; } cout << (int)div - 1; return 0; }
-
-12017-05-08 08:59:25@
语言题?懵.jpg
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <iomanip> #include <cstdlib> using namespace std; int k; double ans; int main() { cin>>k; int i=0; while(ans<=k) { i++; ans+=1.0/double(i); } cout<<i<<endl; return 0; }