NC220429. BinarySeating
描述
输入描述
The input consists of:•A line with an integer n (1 ≤ n ≤ 40), the number of students.•A line with n integers t1, . . . , tn (1 ≤ ti ≤ 1000): tiis the time it takes for the ith student to fifinish the exam and leave.
输出描述
Output the expected time before you can leave. Your answer should have an absolute or relative error of at most 10−6.
示例1
输入:
2 2 3
输出:
2
示例2
输入:
5 1 4 5 2 3
输出:
4.03125
示例3
输入:
5 2 1 1 1 1
输出:
1.46875
C++(clang++11) 解法, 执行用时: 3ms, 内存消耗: 476K, 提交时间: 2021-04-11 17:12:10
#include <bits/stdc++.h> using namespace std; int n,a[100]; double ans,t=0.5; int main(){ cin>>n; for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); for(int i=n-1;i>=0;i--){ ans+=t*a[i]; t/=2; } printf("%.6lf\n",ans); }
pypy3(pypy3.6.1) 解法, 执行用时: 45ms, 内存消耗: 22736K, 提交时间: 2021-04-14 09:06:50
n = int(input()) a = map(int, input().split()) i, ans = 0, 0 for x in sorted(a): ans = ans + x * (1 << i) / (1 << n) i += 1 print(ans)
Python3(3.9) 解法, 执行用时: 41ms, 内存消耗: 6872K, 提交时间: 2021-04-11 14:16:21
n = int(input()) t = list(map(int,input().split())) t.sort() fm = 2**n s = 0 for i in range(n): s+=2**i*t[i] jg = s/fm print(jg)