zoukankan      html  css  js  c++  java
  • 2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure

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

    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 #include <iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstdlib>
     5 #include<cstring>
     6 using namespace std;
     7 double a[1000005];
     8 char ch[1000005];
     9 int n;
    10 int main()
    11 {
    12 
    13     for(int i=1000000;i>=1;i--)
    14      a[i]=a[i+1]+1.0/pow((double)i,2.0);
    15 
    16     while(~scanf("%s",&ch))
    17     {
    18         int len=strlen(ch);
    19         int n=0;
    20         for(int i=0;i<len;i++) {n=n*10+ch[i]-'0'; if (n>1000000) break;}
    21 
    22         if(n>=1000000) printf("%.5lf
    ",a[1]);
    23           else printf("%.5lf
    ",a[1]-a[n+1]);
    24     }
    25     return 0;
    26 }
  • 相关阅读:
    code of C/C++(2)
    code of C/C++ (1)
    dll 的编写和使用
    Python基础练习-数据类型与变量part2
    Python基础练习-数据类型与变量
    python基础练习-循环
    Linux grep
    nginx反向代理
    正则表达式
    Linux samba ing
  • 原文地址:https://www.cnblogs.com/Annetree/p/5879850.html
Copyright © 2011-2022 走看看