zoukankan      html  css  js  c++  java
  • 超级平均数 (Supermean,UVa 10883)

     1 #include <iostream>
     2 #include <string.h>
     3 #include <string>
     4 #include <fstream>
     5 #include <algorithm>
     6 #include <stdio.h>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 using namespace std;
    12 const double eps = 1e-8;
    13 const int INF=0x7fffffff;
    14 unsigned long long uINF = ~0LL;
    15 #define MAXN 10000007
    16 typedef long long LL;
    17 double a[MAXN];
    18 int main()
    19 {
    20     int T,t=1,n;
    21     scanf("%d",&T);
    22     while(T--)
    23     {
    24         scanf("%d",&n);
    25         for(int i=0;i<n;i++)
    26         scanf("%lf",&a[i]);
    27         double ans=0,temp=0;
    28         for(int i=0;i<n;i++)
    29         {
    30         if(a[i]>0)ans+=exp(log(a[i])+temp-(n-1)*log(2));
    31         if(a[i]<0)ans-=exp(log(-a[i])+temp-(n-1)*log(2));
    32 
    33         temp=temp+log(n-i-1)-log(i+1);
    34         }
    35         //cout<<ans<<endl;
    36         printf("Case #%d: %.3lf
    ",t++,ans);
    37     }
    38 
    39     return 0;
    40 }

    数字范围 太大 化成指数运算  log c(n,k+1)-log c(n,k)=log (n-k) - log (k+1)

  • 相关阅读:
    html表单
    html基础
    MySQL数据库 数据的更新
    JAVA数据库编程
    集合框架
    线程和进程
    反射
    centos 7环境
    js中的this
    javascript的作用域以及闭包现象
  • 原文地址:https://www.cnblogs.com/TO-Asia/p/3209940.html
Copyright © 2011-2022 走看看