Cure

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1333    Accepted Submission(s): 440

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
 
 
 
解析:一定要注意这句话“The input file is at most 1M.”坑点所在。输入的长度可能达到1e6。这个极限为PI*PI/6,保留5位小数就是1.64493。n达到1000000左右以后,结果就不会再变了。
 
 
 
#include <cstdio>
#include <cstring> const int MAXN = 1e6+5;
double sum[MAXN];
char s[MAXN]; void init()
{
sum[0] = 0;
for(int i = 1; i <= 1000000; ++i){
sum[i] = sum[i-1]+1.0/(i*1.0*i);
}
} int main()
{
init();
while(~scanf("%s", s)){
int len = strlen(s);
if(len >= 7){
printf("1.64493\n");
continue;
}
int n = 0;
for(int i = 0; i < len; ++i)
n = n*10+s[i]-'0';
printf("%.5f\n", sum[n]);
}
return 0;
}

  

HDU 5879 Cure的更多相关文章

  1. HDU 5879 Cure -2016 ICPC 青岛赛区网络赛

    题目链接 题意:给定一个数n,求1到n中的每一项的平方分之一的累加和. 题解:题目没有给数据范围,而实际上n很大很大超过long long.因为题目只要求输出五位小数,我们发现当数大到一定程度时值是固 ...

  2. HDU 5879 Cure (数论)

    题意:给定n,求前 n 项 1/(k*k) 的和. 析:由于这个极限是 PI * PI / 6,所以我们可以找到分界点,然后计算就好. 代码如下: #pragma comment(linker, &q ...

  3. Cure HDU - 5879(预处理+技巧)

    Cure Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. 【2016 ACM/ICPC Asia Regional Qingdao Online】

    [ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...

  5. 16年青岛网络赛 1002 Cure

    题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=723 Cure Time Limit: 30 ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. 关于navicat连接oracle 报 ORA-12737 set CHS16GBK错误的解决方案

    [转]关于navicat连接oracle 报 ORA-12737 set CHS16GBK错误的解决方案 昨天下载安装了navicat 9.0 Premium(高级英文版),连接mysql正常,看到他 ...

  2. What is the difference between supervised learning and unsupervised learning?

    Machine Learning is a class of algorithms which is data-driven, i.e. unlike "normal" algor ...

  3. windows service 安装和卸载指令

    添加服务: cd C:\Windows\Microsoft.NET\Framework\v4.0.30319InstallUtil.exe D:\OneKeyWebSiteDeployment\Ser ...

  4. cf div2 235 D

    D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...

  5. java基础知识回顾之javaIO类--File类应用:递归深度遍历文件

    代码如下: package com.lp.ecjtu.File.FileDeepList; import java.io.File; public class FileDeepList { /** * ...

  6. 欧拉工程第62题:Cubic permutations

    题目链接 找出最小的立方数,它的各位数的排列能够形成五个立方数 解决关键点: 这五个数的由相同的数组成的 可以用HashMap,Key是由各位数字形成的key,value记录由这几个数组成的立方数出现 ...

  7. NSDictionary 初始化

    NSDictionary *dic1=[NSDictionary dictionaryWithObject:@"1" forKey:@"a"];         ...

  8. 通过数据库表自动生成POJO(JavaBean)对象

    主类: package bqw.tool; import java.util.ResourceBundle;import java.sql.DriverManager;import java.sql. ...

  9. 语言基础:C#输入输出与数据类型及其转换

    今天学习了C#的定义及特点,Visual Studio.Net的集成开发环境和C#语言基础. C#语言基础资料——输入输出与数据类型及其转换 函数的四要素:名称,输入,输出,加工 输出 Console ...

  10. .net通过获取客户端IP地址反查出用户的计算机名

    这个功能看似很少用到,但又非常实用,看似简单,但又在其中存在很多未知因素造成让人悲痛莫名的负能量... 这是公司内部最近在使用的功能,因为是DHCP,所以有时会根据计算机名做一些统计和权限的设置. 也 ...