题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5003
Problem Description
Osu! is a famous music game that attracts a lot of people. In osu!, there is a performance scoring system, which evaluates your performance. Each song you have played will have a score. And the system will sort all you scores in descending order. After that, the i-th song scored a
i will add 0.95^(i-1)*a
i to your total score.
Now you are given the task to write a calculator for this system.
Now you are given the task to write a calculator for this system.
Input
The first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains an integer n, denoting the number of songs you have played. The second line contains n integers a 1, a 2, ..., a n separated by a single space, denoting the score of each song.
T<=20, n<=50, 1<=a i<=500.
For each test case, the first line contains an integer n, denoting the number of songs you have played. The second line contains n integers a 1, a 2, ..., a n separated by a single space, denoting the score of each song.
T<=20, n<=50, 1<=a i<=500.
Output
For each test case, output one line for the answer.
Your answers will be considered correct if its absolute error is smaller than 1e-5.
Your answers will be considered correct if its absolute error is smaller than 1e-5.
Sample Input
1 2 530 478
Sample Output
984.1000000000
Source
2014 ACM/ICPC Asia Regional Anshan Online
代码:
代码:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;
#define min2(x, y) min(x, y)
#define max2(x, y) max(x, y)
#define min3(x, y, z) min(x, min(y, z))
#define max3(x, y, z) max3(x, max(y, z))
#define clr(x, y) memset(x, y, sizeof(x))
#define fr(i,n) for(int i = 1; i <= n; i++)
#define upfr(i,j,n) for(int i = j; i <= n; i++)
#define dowfr(i,j,n) for(int i = n; i >= j; i--)
#define scf(n) scanf("%d", &n)
#define ptf(n) printf("%d",n)
#define ptfs(s) printf("%s",s)
#define ptln() printf("\n")
#define srt(a,n) sort(a,n)
#define LL long long
#define pi acos(-1.0)
#define inf 1 << 31-1
#define eps 0.00001
#define maxn 55
int arr[maxn];
int cmp(int a, int b)
{
return a > b;
}
int main()
{
//freopen("D:\\ACM Contest\\2014 ACM\\2014 ACMICPC Asia Regional Anshan Online\\in.txt","r",stdin);
int t;
scf(t);
while(t--)
{
int n;
scf(n);
fr(i,n)
scanf("%d ", &arr[i]);
sort(arr+1, arr+1+n, cmp);
double sum = 0;
fr(i,n)
{
double tmp = 1;
fr(j,i-1)
tmp *= 0.95;
sum += tmp * arr[i];
}
printf("%.10lf\n", sum);
}
return 0;
}