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

Cure

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

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
 
题目大意:输入一个整数n,输出1/(k平方)的和(k的范围为1……n)保留五位小数;
解题思路:由于n不断地增加,1/(k平方)的和逐渐的趋于稳定,对于该题来说,由于输出结果要求保留五位小数,
     所以当n增大到12万左右的时候前五位小数就基本保持不变啦,所以对于超过12万的n来说只需要输出一
     个固定的值即可。
AC代码:
 #include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std; int main ()
{
double n,m;
int i;
while(~scanf("%lf",&n)){
m=;
if(n<){ //对于12万以内的数按要求计算结果即可,超过12万输出1.64493
for(i=;i<=n;i++){
m+=1.0/i/i;
}
printf("%.5lf\n",m);
}else{
printf("%.5lf\n",1.64493);
}
}
return ;
}

16年青岛网络赛 1002 Cure的更多相关文章

  1. 16年青岛网络赛 1001 I Count Two Three

    题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=723 I Count Two ThreeTi ...

  2. HDU 4739 Zhuge Liang's Mines (2013杭州网络赛1002题)

    Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  4. 2016ACM-ICPC Qingdao Online青岛网络赛题解

    TonyFang+Sps+我=5/12 滚了个大粗 2016年9月21日16:42:36 10题完工辣 01 题意:求形同的数中大于n的最小值 题解:预处理所有的(5194个),在这里面二分 #inc ...

  5. 2018 icpc 青岛网络赛 J.Press the Button

    Press the Button Time Limit: 1 Second      Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...

  6. HDU 6212 Zuma 2017青岛网络赛 区间DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6212 解法:看了眼题就发现这个BZOJ 1032不是一毛一样?但是BZOJ上那是个巨坑,数据有错,原来 ...

  7. 青岛网络赛J-Press the button【暴力】

    Press the Button Time Limit: 1 Second      Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...

  8. The 2018 ACM-ICPC Asia Qingdao Regional Contest(青岛网络赛)

    A Live Love 水 #include <algorithm> #include<cstdio> #include<cstring> using namesp ...

  9. HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)

    背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即 if(val + (LD)pk[d].val / (LD)pk[d]. ...

随机推荐

  1. php中的json_encode()和json_decode()函数的一些说明

    一,json语法( php中的json_decode($json)中的$json要符合json语法格式 ) ① JSON可以表示三种类型的值 1,简单值.包括整型,字符串型,布尔值和null.例如:5 ...

  2. eclipse + maven 搭建springMVC+Spring+mybatis 系统

    首先需要下载maven 安装maven插件.自行百度. 1: 创建maven系统 http://huxiaoheihei.iteye.com/blog/1766986 2:添加pom依赖: pom.x ...

  3. JSP 中EL表达式用法详解

    EL 全名为Expression Language EL 语法很简单,它最大的特点就是使用上很方便.接下来介绍EL主要的语法结构: ${sessionScope.user.sex} 所有EL都是以${ ...

  4. Java 序列化 反序列化 历史版本处理

    直接引用  http://www.cnblogs.com/xdp-gacl/p/3777987.html

  5. 转json using指令

    using Newtonsoft.Json;using Newtonsoft.Json.Converters; string result = JsonConvert.SerializeObject( ...

  6. OneSQL的docker之旅

      百度盘下载地址: http://pan.baidu.com/s/1v9GWA   OneSQL Docker使用方法:  1. 解压    tar zxvf OneSql-Docker-5.6.2 ...

  7. 【转】selenium之 定位以及切换frame

    转载自:http://www.voidcn.com/blog/huilan_same/article/p-6155896.html 很多人在用selenium定位页面元素的时候会遇到定位不到的问题,明 ...

  8. JfreeChart的使用

    前提:导入需要的2个jar文件,jcommon-版本号.jar,jfreechart-版本号.jar.可以去官网下载:http://sourceforge.net/projects/jfreechar ...

  9. 读javascript高级程序设计06-面向对象之继承

    原型链是实现继承的主要方法,通过原型能让一个引用类型继承另一个引用类型. 1.原型链实现继承 function SuperType(){ this.superprop=1; } SuperType.p ...

  10. zookeeper学习系列:三、利用zookeeper做选举和锁

    之前只理解zk可以做命名,配置服务,现在学习下他怎么用作选举和锁,进一步还可构建master-slave模式的分布式系统. 为什么叫Zoo?“因为要协调的分布式系统是一个动物园”. ZooKeeper ...