Bootstrap

MT2092 水温调节

 代码:

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

int main()
{
    double t1, t2, x1, x2, t0;
    double y1, y2, t;
    double tmax = 0x3f3f3f3f, ans1, ans2;
    cin >> t1 >> t2 >> x1 >> x2 >> t0;
    y1 = x1, y2 = x2; // 初始流速赋最大
    while (y1 >= 0 && y2 >= 0)
    {
        t = (t1 * y1 + t2 * y2) / (y1 + y2);
        if (t >= t0) // 温度高:降低热水流速
        {
            if (t < tmax)
            {
                tmax = t;
                ans1 = y1;
                ans2 = y2;
            }
            y2--;
        }
        else // 温度低:降低冷水流速
        {
            y1--;
        }
    }
    cout << ans1 << " " << ans2;
    return 0;
}

;