问题 E: Pesky Publicans
问题 E: Pesky Publicans
时间限制: 1 Sec 内存限制: 128 MB
题目描述
Tax collectors in the Roman empire, called publicans, are not well perceived, and for good reason. However, they are necessary for the running of the empire. Your job is to estimate how much money Rome will receive in taxes. Not everyone pays, but at least one person is guaranteed to pay. The trouble is you can never really know who will and won’t pay.
Given a list of what citizens would pay if they did pay taxes,output the average of all possible sums of taxes received.
输入
The first line of the input will be a single integer, n ≤ 1, 000. There will be n test cases that follow.
Each test case begins with a single integer p denoting the number of people in Rome, 1 ≤ p ≤ 10, 000. The next line will contain p space separated integers, 0 < vi < 10, 000,denoting the amount of taxes that each citizen would pay if they decided to pay.
输出
Each test case should contain a single floating point number denoting the average taxes paid, accurate and truncated to three decimal places.
样例输入 Copy
2
5
1 2 3 4 5
5
10 11 12 13 14
样例输出 Copy
7.742
30.968
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include<cmath>
using namespace std;
long long qmi(int a, int k)//快速幂
{
long long res = 1;
while(k)
{
if(k & 1)res *= a;
a *= a;
k >>= 1;
}
return res;
}
int main()
{
int T;
cin >> T;
while(T -- )
{
int n;
cin >> n;
double res = 0;
for(int i = 0; i < n; i ++ )
{
int x;
cin >> x;
res += x;
}
if(n >= 55)
printf("%.3lf\n", res / 2);
else
{
double a = pow(2, n - 1);
double b = pow(2, n) - 1;
printf("%.3lf\n",res * a / b);
}
}
return 0;
}

浙公网安备 33010602011771号