首页 > 代码库 > HDU5879(打表)
HDU5879(打表)
Cure
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 293 Accepted Submission(s): 96
Problem Description
Given an integer n, we only want to know the sum of 1/k2 where k from 1 to n.
Input
There are multiple cases.
For each test case, there is a single line, containing a single positive integer n.
The input file is at most 1M.
For each test case, there is a single line, containing a single positive integer n.
The input file is at most 1M.
Output
The required sum, rounded to the fifth digits after the decimal point.
Sample Input
1
2
4
8
15
Sample Output
1.00000
1.25000
1.42361
1.52742
1.58044
Source
2016 ACM/ICPC Asia Regional Qingdao Online
n没有给出范围,意思就是默认无限大。。。。。比赛时被坑了,不停RE。
1 //2016.9.17 2 #include <iostream> 3 #include <cstdio> 4 5 using namespace std; 6 7 double sum[54000]; 8 9 int main()10 {11 int n;12 double ans;13 ans = 0;14 sum[0] = 0;15 for(int i = 1; i <= 53000; i++)16 {17 ans += (1.0/i)*(1.0/i); 18 sum[i] = ans;19 }20 string s;21 while(cin>>s)22 {23 int len = s.length();24 n = 0;25 for(int i = 0; i < len; i++)26 {27 n = n*10+s[i]-‘0‘;28 if(n > 120000)break;29 }30 if(n >= 110291)ans = 1.64493;31 else if(n >= 52447)ans = 1.64492;32 else ans = sum[n];33 printf("%.5lf\n", ans);34 }35 36 return 0;37 }
HDU5879(打表)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。