2020年团体程序设计天梯赛 L1-4 调和平均

思路:

水题,略过

Tip:

注意for循环中不要cin读入double数组,队友亲自实验读入数组会WA测试点2

#include <bits/stdc++.h>

using namespace std;

int main() {
    double n;
    double ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        double tmp;
        cin >> tmp;
        tmp = 1.0 / tmp;
        ans += tmp;
    }
    ans = n/ans;
    printf("%.2lf",  ans);
    return 0;
}

  

posted @ 2020-11-29 15:35  Whiteying  阅读(192)  评论(0编辑  收藏  举报