C

来源:互联网 发布:seo蜘蛛精怎么用 编辑:程序博客网 时间:2024/06/15 04:12

Think:
1>题意:已知冷水温度t1,热水温度t2,冷水最高释放速度x1,热水最高释放速度x2,问如何控制释放速度可使最快达到正趋向于温水温度t0
1>题意建模:两个水杯温度分别为t1, t2, 体积分别为x1, x2,要得到温度正趋向于温度t0(t0介于t1和t2之间)的最大体积
2>贪心:从最大冷水体积x1开始试探,让最大热水体积x2递减,若混合温度低于t0,则x1-1,最后保留的试探解即为最优解

C - Hot Bath CodeForces - 127CBob is about to take a hot bath.There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can transmit from 0 to x2 water units per second.If y1 water units per second flow through the first tap and y2 water units per second flow through the second tap, then the resulting bath water temperature will be:

这里写图片描述

Bob wants to open both taps so that the bath water temperature was not less than t0. However, the temperature should be as close as possible to this value. If there are several optimal variants, Bob chooses the one that lets fill the bath in the quickest way possible.Determine how much each tap should be opened so that Bob was pleased with the result in the end.

Input

You are given five integers t1, t2, x1, x2 and t0 (1 ≤ t1 ≤ t0 ≤ t2 ≤ 106, 1 ≤ x1, x2 ≤ 106).

Output

Print two space-separated integers y1 and y2 (0 ≤ y1 ≤ x1, 0 ≤ y2 ≤ x2).

Example
Input

10 70 100 100 25Output99 33Input300 500 1000 1000 300Output1000 0Input143 456 110 117 273Output76 54

Note

In the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible.

以下为Accepted代码

#include <bits/stdc++.h>#define ULL unsigned long long#define LL long longusing namespace std;int main(){    LL t1, t2, x1, x2, t0, res_x1, res_x2;    double t, ct;    while(scanf("%lld %lld %lld %lld %lld", &t1, &t2, &x1, &x2, &t0) != EOF){        ct = 1e104;        while(x1 >= 0 && x2 >= 0){            t = (double)(t1*x1 + t2*x2)/(x1+x2);            if(t < t0){                x1--;                continue;            }            if(t < ct){                ct = t;                res_x1 = x1;                res_x2 = x2;            }            x2--;        }        printf("%lld %lld\n", res_x1, res_x2);    }    return 0;}
原创粉丝点击