NC236485. Glass Bead Game
描述
输入描述
The first line contains an integer ().
The second line contains real numbers each with 6 digits of precision.
输出描述
Output one real number, the answer.
Your answer will be considered correct if its absolute or relative error does not exceed . Formally let your answer be , jury answer be . Your answer will be considered correct if .
示例1
输入:
2 0.500000 0.500000
输出:
0.500000000000000
示例2
输入:
3 0.500000 0.250000 0.250000
输出:
0.916666666666667
C++(clang++ 11.0.1) 解法, 执行用时: 3ms, 内存消耗: 468K, 提交时间: 2023-05-03 14:25:09
#include <bits/stdc++.h> using namespace std; #define N 105 int n; double p[N],g; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>p[i]; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) g+=(p[i]*p[j])/(p[i]+p[j]); printf("%.9lf\n",g*2); }
pypy3 解法, 执行用时: 128ms, 内存消耗: 26976K, 提交时间: 2022-04-18 10:09:57
n = int(input()) ans = 0 p = list(map(float, input().split())) ans = 0 for i in range(n): for j in range(n): if i != j: ans += p[i]*p[j]/(p[i]+p[j]) print(ans)
Python3 解法, 执行用时: 44ms, 内存消耗: 4544K, 提交时间: 2022-04-21 10:38:34
n=input() p=list(map(float,input().split())) ans=0 for i,pi in enumerate(p): for j,pj in enumerate(p): if i!=j: ans+=pi*pj/(pi+pj) print(ans)