zoukankan      html  css  js  c++  java
  • 16年青岛网络赛 1002 Cure

    题目链接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代码:
     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<string.h>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 int main ()
     8 {
     9     double n,m;
    10     int i;
    11     while(~scanf("%lf",&n)){
    12         m=0;
    13         if(n<120000){  //对于12万以内的数按要求计算结果即可,超过12万输出1.64493 
    14             for(i=1;i<=n;i++){
    15             m+=1.0/i/i;
    16             }
    17             printf("%.5lf
    ",m);
    18         }else{
    19             printf("%.5lf
    ",1.64493);
    20         }
    21     }
    22     return 0;
    23 }
    View Code
  • 相关阅读:
    systemd 介绍
    Goland读取配置文件--viper包
    Goland日志记录
    进程查询端口占用
    Python zip() 函数
    Jenkins权限管理(角色权限)
    Django ORM查询总结
    如何查看windows计算机重启记录
    Django ORM迁移
    Django中文乱码解决
  • 原文地址:https://www.cnblogs.com/yoke/p/5896993.html
Copyright © 2011-2022 走看看