Hot Bath

Description

Bob 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 t1t2x1x2 and t0 (1 ≤ t1 ≤ t0 ≤ t2 ≤ 1061 ≤ x1, x2 ≤ 106).

Output

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

Sample Input

Input
10 70 100 100 25
Output
99 33
Input
300 500 1000 1000 300
Output
1000 0
Input
143 456 110 117 273
Output

76 54





题意:

给出整数t1,t2,x1,x2,t0,和公式(1 ≤ t1 ≤ t0 ≤ t2 ≤ 1061 ≤ x1, x2 ≤ 106).求满足(0 ≤ y1 ≤ x10 ≤ y2 ≤ x2)此条件的y1,y2使得t最接近t0,但要保证t>t0.输出y1,y2.多种方案时输出最大的y1,y2.

题解:不4个特判必WA。不过这4个特判不太容易想全。

case 1:t1==t0 && t2!=t0 => y1=x1,y2=0

case 2:t2==t0 && t1!=t0 => y1=0,y2=x2

case 3:t1==t2 =>y1=x1,y2=x2

做法:

枚举y1,然后t2可以解出来。在选最小的,不过也有坑!见程序吧

case 4:非常难想到的是,当y1==0,方程解出y2=0此时显然不对,所以此种情况仍需处理。

[cpp]  view plain  copy
  1. #include<iostream>  
  2. #include<cstring>  
  3. using namespace std;  
  4. long long t1,t2,x1,x2,t0,f1,f2;  
  5. long long cal(long long t1,long long y1,long long t2,long long y2)  
  6. {  
  7.     return t1*y1+t2*y2-t0*(y1+y2);  
  8. }  
  9. void solve(long long y1,long long y2)  
  10. {  
  11.     if(y2<0)y2=0;else if(y2>x2)y2=x2;//溢出  
  12.     if(y1==0 && y2==0)return;//WA  
  13.   
  14.     if(t1*y1+t2*y2<t0*(y1+y2))return;//不满足t>=t0的条件  
  15.     if(cal(t1,y1,t2,y2)*(f1+f2)<cal(t1,f1,t2,f2)*(y1+y2)||(f1<0 && f2<0))  
  16.     {  
  17.         f1=y1;f2=y2;  
  18.     }  
  19.     else  
  20.     if(cal(t1,y1,t2,y2)*(f1+f2)==cal(t1,f1,t2,f2)*(y1+y2)&&y1+y2>f1+f2)  
  21.     {  
  22.         f1=y1;f2=y2;  
  23.     }  
  24. }  
  25. int main()  
  26. {  
  27.     long long y2;  
  28.     while(cin>>t1>>t2>>x1>>x2>>t0)  
  29.     {  
  30.         f1=-1,f2=-1;  
  31.         if(t1==t2)//case  
  32.         {  
  33.             f1=x1;f2=x2;  
  34.         }  
  35.         else if(t1==t0)//case  
  36.         {  
  37.             f1=x1;f2=0;  
  38.         }  
  39.         else if(t2==t0)//case  
  40.         {  
  41.             f1=0;f2=x2;  
  42.         }  
  43.         else  
  44.         for(long long y1=1;y1<=x1;y1++)  
  45.         {  
  46.             if(t0>t2)  
  47.             {  
  48.                 y2=(t1*y1-t0*y1)/(t0-t2);  
  49.                 solve(y1,y2);  
  50.             }  
  51.             else  
  52.             if(t0<t2)  
  53.             {  
  54.                 y2=(t1*y1-t0*y1)%(t0-t2)==0?(t1*y1-t0*y1)/(t0-t2):1+(t1*y1-t0*y1)/(t0-t2);  
  55.                 solve(y1,y2);  
  56.             }  
  57.         }  
  58.         //y1=0 case 4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
  59.         if(t2>=t0)solve(0,x2);  
  60.   
  61.         cout<<f1<<" "<<f2<<endl;  
  62.     }  
  63.     return 0;  
  64. }  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值