题意:给你一个数组a,降序排序后,求sum+=0.95^(i-1)*ai
这题wa了两发,因为我没看清题意,要排序!
精度上面通过a^(i-1)=e^((i-1)*log(a))
提到精度,就要想到底数
代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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\n",ans); 28 } 29 return 0; 30 }