zoukankan      html  css  js  c++  java
  • hdoj 5003

         题意:给你一个数组a,降序排序后,求sum+=0.95^(i-1)*ai

          这题wa了两发,因为我没看清题意,要排序!

          精度上面通过a^(i-1)=e^((i-1)*log(a))

          提到精度,就要想到底数

          代码

     1 #include "stdio.h"
     2 #include "string.h"
     3 #include "math.h"
     4 #include "algorithm"
     5 #define MAX 55
     6 using namespace std;
     7 int a[MAX];
     8 int cmp(int a,int b)
     9 {
    10     return a>b;
    11 }
    12 int main()
    13 {
    14     int n,i,j;
    15     double ans;
    16     int t;
    17     scanf("%d",&t);
    18     while(t--)
    19     {
    20         scanf("%d",&n);
    21         for(i=1;i<=n;i++)
    22                 scanf("%d",&a[i]);
    23         sort(a+1,a+1+n,cmp);
    24         ans=0;
    25         for(i=1;i<=n;i++)
    26                ans=ans+(double)a[i]*pow(2.718281828459,(double)(i-1)*log(0.95));
    27         printf("%.10f
    ",ans);
    28     }
    29     return 0;
    30 }
    View Code
  • 相关阅读:
    nconf修改密码
    快速清空一个文
    freebsd安装snmp
    -bash: mail: command not found
    重置Cacti密码
    cacti添加被监控机全过程
    cacti图形字符乱码
    博客链接
    tar命令详解
    MainPresenter 实现类
  • 原文地址:https://www.cnblogs.com/Blundering-Chen/p/3974525.html
Copyright © 2011-2022 走看看