1 条题解

  • 0
    @ 2036-1-26 17:26:19

    练14.2 平均分

    解题思路

    总成绩为 87x+85y,除以总人数 x+y 得全班平均。

    正确性说明

    按人数加权求和得到所有学生总分,再除人数就是总体平均。

    易错点

    不能直接平均 87 与 85;保留四位小数。

    复杂度

    本题输入规模固定,时间 O(1),额外空间 O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        double x, y;
        cin >> x >> y;
        cout << fixed << setprecision(4) << (87 * x + 85 * y) / (x + y) << "\n";
        return 0;
    }
    
    • 1