fork(7) download
  1. #include <cstdio>
  2. double c_price( double p, double p1, double s1, double p2, double s2 )
  3. {
  4. //if given solutions' concentrations and the result are equal
  5. if ( p1 == p2 && p2 == p )
  6. {
  7. //choose the least price
  8. if( s1 > s2 ) return s2;
  9. return s1;
  10. }
  11. else if ( p1 == p2 && p1 != p ) return 0;
  12.  
  13. if ( p1 == p ) return s1;
  14. if ( p2 == p ) return s2;
  15.  
  16. //else solve the system of equations
  17. double a1 = ( p - p1 ) / ( p2 - p1 ); if ( a1 > 1 || a1 < 0 ) return 0;
  18. double a2 = 1 - a1;
  19. return s1*a1+s2*a2;
  20. }
  21.  
  22. int main()
  23. {
  24. double p1, p2, p3, f_p;
  25. double s1, s2, s3;
  26.  
  27. scanf("%lf %lf %lf %lf", &p1, &p2, &p3, &f_p);
  28. scanf("%lf %lf %lf", &s1, &s2, &s3);
  29.  
  30. double s12 = c_price( f_p, p1, s1, p2, s2 );
  31. double s13 = c_price( f_p, p1, s1, p3, s3 );
  32. double s23 = c_price( f_p, p2, s2, p3, s3 );
  33.  
  34. if( !s12 && !s13 && !s23 ) { printf("Impossible!\n"); return 0; }
  35.  
  36. double min_price = s12; //choose the least price
  37. if ( min_price > s13 && s13 ) min_price = s13; //"&& s23" is equal to "s23 is correct" statement
  38. if ( min_price > s23 && s23 ) min_price = s23;
  39. printf("%.2lf", min_price);
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 3300KB
stdin
Standard input is empty
stdout
Impossible!