【深基2.例8】再分肥宅水 · 教师题解

【深基2.例8】再分肥宅水

解题思路

每人饮料为 t/n 毫升,杯子总数为 2n。

正确性说明

均分定义就是总量除人数;每人两杯乘人数得到总杯数。

易错点

饮料用 double;第一行严格三位小数,第二行整数。

复杂度

时间 O(1),空间 O(1)。

参考代码(C++11)

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    double t;
    int n;
    cin >> t >> n;
    cout << fixed << setprecision(3) << t / n << "\n" << 2 * n << "\n";
    return 0;
}
返回题目