271 条题解
-
0yujinhan LV 8 @ 2018-08-07 16:06:00
C++AC标程(2):
#include<bits/stdc++.h> //万能头文件,这是可以用的!!好开森!
using namespace std;
int main()
{
int k,i=0;
double s=0.0000;
cin>>k;
do
{
i++;
s=s+ (1.0/i);
}
while (s<=k);
printf("%d",i);
return 0;
} -
02016-09-17 10:17:57@
样例我虽不对,但满分
-
02016-03-06 19:49:46@
#include <iostream> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <algorithm> #include <math.h> using namespace std; long long a[16]{0,2,4,11,31,83,227,616,1674,4550,12367,33617,91380,248397,675214,1835421}; int main(){ int k; scanf("%d",&k);a printf("%lld",a[k]); return 0; }
-
02016-03-02 14:50:39@
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>using namespace std;
long long a[16]{0,2,4,11,31,83,227,616,1674,4550,12367,33617,91380,248397,675214,1835421};
int main(){
int k;
scanf("%d",&k);
printf("%lld",a[k]);
return 0;
}
表一发 -
02016-01-18 20:18:13@
var
i,j,k,o,p,n,m:longint;
ans:real;
begin
read(k);
i:=0;
while ans<=k do
begin
inc(i);
ans:=ans+1/i;
end;
writeln(i);
end. -
02015-11-01 11:11:38@
忽然发现有人用公式做的。
根据欧拉公式S=1+1/2+1/3+1/4+1/5+...+1/n=ln(n)+γ
∴n=e^(S-C)
盗一下楼上的代码。
##Lang: C++#include <iostream>
#include <cmath>
using namespace std;int main(){
int k;
cin >> k;
cout << int(exp(k - 0.577215) + 0.5) << endl;return 0;
} -
02015-11-01 10:45:46@
先写个打表程序。
/*
ID:
LANG:
TESK:
/
#include <iostream>
#include <fstream>
//#include <cstdio>
//#include <cstdlib>
//#include <string>
//#include <cstring>
//#include <cmath>
//#include <algorithm>
using namespace std;
typedef long long longint;
const string file_name = "p1127";
const string file_in_name = file_name+"in";
const string file_out_name = file_name+".out";
const int N=10000000;
//const int M=100;
longint k;
long double p[N]={0,1};
int main()
{
//ifstream cin(file_in_name.c_str(),ios::in);
//ofstream cout(file_out_name.c_str(),ios::out);
//freopen(file_in_name.c_str(),"r",stdin);
freopen(file_out_name.c_str(),"w",stdout);
for(int i=2;i<N;i++)
p[i]=p[i-1]+1.0/i;
for(k=1;k<=15;k++){
longint n=1;
while(p[n]<=k)n++;
cout<<n<<',';
}
//cin.close();
//cout.close();
return 0;
}
然后秒过。
/
ID:
LANG:
TESK:
*/
#include <iostream>
#include <fstream>
//#include <cstdio>
//#include <cstdlib>
//#include <string>
//#include <cstring>
//#include <cmath>
//#include <algorithm>
using namespace std;
typedef long long longint;
const string file_name = "p1127";
const string file_in_name = file_name+"in";
const string file_out_name = file_name+".out";
const int N=15;
//const int M=100;
longint k;
longint p[N]={2,4,11,31,83,227,616,1674,4550,12367,33617,91380,248397,675214,1835421};
int main()
{
//ifstream cin(file_in_name.c_str(),ios::in);
//ofstream cout(file_out_name.c_str(),ios::out);
//freopen(file_in_name.c_str(),"r",stdin);
//freopen(file_out_name.c_str(),"w",stdout);
cin>>k;
cout<<p[k-1];
//cin.close();
//cout.close();
return 0;
} -
02015-10-31 17:11:43@
var
k,n:longint;
s:real;
begin
readln(k);
s:=1;n:=1;
while s<k do
begin
inc(n);
s:=s+1/n;
end;
writeln(n);
end. -
02015-10-25 19:55:11@
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <functional>
#include <cmath>
using namespace std;
int main()
{
double x;
double sum;
double k;
x = 1;
sum = 0;
cin >> k;
while (sum <= k)
{
sum += 1 / x;
x++;
}
cout << x - 1 << endl;
return 0;
} -
02015-09-01 13:46:12@
#include <cstdio>
int main()
{
int N=0;
double res=0.0;
double K;scanf("%lf",&K);
while(res<=K) {
res+=1.0/(double)(++N);
}
printf("%d",N);
return 0;
} -
02015-08-18 20:44:01@
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int k=scanner.nextInt();
double sum=1;
double i=2;;
while (sum<=k) {
sum+=1/i;
i+=1;
}System.out.print((int)--i);
}}
-
02015-08-13 21:56:41@
waterful。
-
02015-08-13 21:56:38@
waterful。
-
02015-08-13 21:56:33@
waterful。
-
02015-05-02 11:30:54@
/*************************************************************************
> File Name: 1127.cpp
> Author: Netcan
> Blog: http://www.netcan.xyz
> Mail: 1469709759@qq.com
> Created Time: Sat 02 May 2015 11:27:02 CST
************************************************************************/#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <sstream>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <stack>
#include <set>
#include <numeric>
#include <utility>
#include <cstring>
using namespace std;int main()
{
int k;
while(scanf("%d", &k) == 1) {
int n=0;
double Sn = 0.0;
while(++n) {
Sn+=1.0/n;
if(Sn > k)
break;
}
printf("%d\n", n);
}return 0;
} -
02015-01-09 19:21:46@
###Lang: C++
#include <iostream>
#include <cmath>
using namespace std;int main(){
int k;
cin >> k;
cout << int(exp(k - 0.577215) + 0.5) << endl;return 0;
} -
02014-11-04 13:36:18@
var n,k:longint;
s:extended;
begin
readln(k);
n:=0;
s:=0;
repeat
inc(n);
s:=s+1/n;
until s>k;
writeln(n);
end. -
02014-10-24 23:01:06@
别忘了用extended。
waterful。
var n,k:longint;
s:extended;
begin
readln(k);
n:=0;
s:=0;
repeat
inc(n);
s:=s+1/n;
until s>k;
writeln(n);
end. -
02014-10-05 21:10:45@
#include <cstdio>
double sum(0.0);
unsigned long long int k, n(0ULL);int main()
{
using namespace std;scanf("%llu", &k);
while (sum <= k)
{
++n;
sum += 1.0 / n;
}printf("%llu", n);
return 0;
} -
02014-08-01 17:08:40@
水题~~
记录信息
评测状态 Accepted
题目 P1127 级数求和
递交时间 2014-08-01 17:07:07
代码语言 C++
评测机 VijosEx
消耗时间 30 ms
消耗内存 272 KiB
评测时间 2014-08-01 17:07:14
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 268 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 272 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 272 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 268 KiB, score = 10
Accepted, time = 30 ms, mem = 272 KiB, score = 50