HDU5879(打表)
2016-09-17 20:08
351 查看
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.
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。//2016.9.17 #include <iostream> #include <cstdio> using namespace std; double sum[54000]; int main() { int n; double ans; ans = 0; sum[0] = 0; for(int i = 1; i <= 53000; i++) { ans += (1.0/i)*(1.0/i); sum[i] = ans; } string s; while(cin>>s) { int len = s.length(); n = 0; for(int i = 0; i < len; i++) { n = n*10+s[i]-'0'; if(n > 120000)break; } if(n >= 110291)ans = 1.64493; else if(n >= 52447)ans = 1.64492; else ans = sum ; printf("%.5lf\n", ans); } return 0; }
相关文章推荐
- 彩虹七色的RGB值
- phpstorm 2016.2 的最新破解方法(截止2016-8-1)
- 只是不想生活在最底层
- WebService(1)_WebService概述
- Java NIO使用及原理分析(二)
- Failed to load resource: the server responded with a status of 406 (Not Acceptable)
- I2S协议
- C/S模型 多线程服务器实现简单计算工作并回馈客户端
- ubuntu /etc/profile和/etc/environment的比较
- 6-文件IO-文件描述符与lseek
- 数字电路系列
- java笔记--day11--类object之hashCode() and getClass()
- Spring-2 配置bean
- Effective Java学习笔记 第65条:不要忽略异常
- 第三周 项目四——顺序表应用(1)
- hdu5889 最短路+网络流
- 一个月内发现的第六起 Linux DDoS 木马
- 一个月内发现的第六起 Linux DDoS 木马
- Bit Depth、Color Depth
- activiti搭建(三)整合Modeler