Tuesday, December 4, 2012

MCPC 2012 - Problem B : Minimal and maximal rate

May Allah`s peace , mercy and blessing be upon you

P.S: This is not the original text, I rephrased and summarized the original one because I'm lazy and I couldn't type the whole text. if there is an error it's my mistake.

[B] JCPC:
Chief judge was hospitalized, he was kept in until a test (that returns a positive real number) dropped to 2.0 or less. Given the current result H and number of days D and provided that he is tested every hour and released immediately if result <= 2.0 print the minimum and maximum rate of decrease in this measurement to be released from the hospital after D days, but not after D+1 days.
1 day = 24 hours, very useful information !!!

Input :
T: number of cases.
T lines : H(current measurement) D(number of days)
1<=T<=200, 3<=H<=100, 1<=D<=150

Output:
Single line for each case in the following format : <maximum rate> <minimum rate> rounded to 5 decimal places after decimal point.

Example :
1
5 2
--->
0.06250 0.04225

Contest Analysis :
The problem was the easiest one, for the maximum rate: H-max*24*D = 2 , so max = (H-2)/(D*24).
in the minimum case the result should drop to 2.0 before D+1 days so an hour before D+1 days then
min=(H-2.0)/(((D+1)*24)-1).

Solution in C++:
#include &ltiostream&gt
#include &ltfstream&gt

#define For(i,n) for(int i(0),_n(n);i<_n;++i)

using namespace std;

int main(int argc, char const *argv[]) {
 long long T,H,D;
 double max,min;
 string gc;
 fstream f("jcpc.in");
 f &gt&gt T;
 For(i,T) {
  f &gt&gt H;
  f &gt&gt D;
  max = (H-2.0)/(D*24);
  min = (H-2.0)/(((D+1)*24)-1);
  cout.precision(5);
  cout &lt&lt fixed &lt&lt max &lt&lt " " &lt&lt min &lt&lt endl;
 }
 f.close();
 return 0;
}

No comments:

Post a Comment


Zoli Issam's blog proudly powered by Blogger | All rights reserved Jaw,B 2010-2013