Sunday, December 4, 2016

LightOJ - 1216 - Juice in the Glass

Once upon a time, there lived a mad programmer. He loved to solve creative problems other than anything. His wife loved him quite a lot but disliked his curiosity for the problems. One day he came from office, his wife gave him a glass of cold lime juice. She was in a romantic mood and waiting for some romantic stuff. But the programmer asked her curiously, "If I give u radius of the top and bottom part of the glass and the height, can you come up with the volume of the glass?" His wife became a bit disappointed but as she is smart she replied with a smile, "You already have drunk some juice, and the glass is not full. If I give you the height of the juice, can you find the volume of the remaining juice in the glass?" Then the programmer kissed his wife and said, "You are the best problem setter in the world!"
Now he set the same problem for you. The radius of the upper part r1 and lower part r2 is given. If height of the glass is h and height of the juice is p what is the volume of the juice in the glass?

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing four integers r1 r2 h p (1 ≤ r2 < r1 ≤ 100, 1 ≤ p ≤ h ≤ 100).

Output

For each case, print the case number and the volume of the juice in the glass. Errors less than 10-6 will be ignored.

Sample Input

Output for Sample Input

2
5 2 3 2
5 2 3 3
Case 1: 58.643062867
Case 2: 122.52211349


Solution:

  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. using namespace std;
  4. typedef long long LL;
  5. const int S = 100003;
  6. const int MOD = 1e9+7;
  7. const double pi = 2 * acos (0.0);
  8.  
  9. int _Int(){int x; scanf("%d"&x); return x;}
  10. LL _LLi(){LL x; scanf("%lld"&x); return x;}
  11. void pruts(){puts("-1");exit(EXIT_SUCCESS);}
  12.  
  13. int dirX[] = { 10-101-11-1 };
  14. int dirY[] = { 010-11-1-11 };
  15. int rX[] = { 1122-1-1-2-2 };
  16. int rY[] = { 2-21-12-21-1 };
  17.  
  18. template < class T > T tri_Area( T x1, T y1, T x2, T y2, T x3, T y3 ){ return abs( x1*( y2-y3 ) - y1*( x2-x3 ) + ( x2*y3-x3*y2 ) );};
  19. template < class T > T Distance( T x1, T y1, T x2, T y2 ){ return sqrt( ( x1-x2 ) * ( x1-x2 ) + ( y1-y2 ) * ( y1-y2 ) ); };
  20. template < class T > T bigMod( T n, T p, T m ){ if( p == 0 )return 1; if( p&1 )return ( n*bigMod( n, p-1, m ) )%m; T x = bigMod( n, p/2, m ); return ( x*)%m; };
  21.  
  22. int sset(int N, int pos){return N=N|(1<<pos);}
  23. bool check(int N, int pos){return (bool)(N&(1<<pos));}
  24. int reset(int N, int pos){return N=N&~(1<<pos);}
  25. /*******************###########################################********************
  26. ********************##   MD. YA-SEEN ARAFAT(ThunderStroke)   ##********************
  27. ********************##    CSE, University of Asia Pacific    ##********************
  28. ********************###########################################********************/
  29.  
  30. void Love(){
  31.     int t = _Int(), cs = 0;
  32.     while( t-- ){
  33.         double r1, r2, h, p;
  34.         scanf( "%lf %lf %lf %lf"&r1, &r2, &h, &);
  35.         double r = r2 + ( ( p/) * ( r1-r2 ) );
  36.         r *= 2.0;
  37.         r2 *= 2.0;
  38.         double ans = ( pi*) / 12;
  39.         ans *= ( ( r*) + ( r2*r2 ) + ( r*r2 ) );
  40.         printf( "Case %d: %.8lf\n"++cs, ans );
  41.     }
  42. }
  43.  
  44. int main(){
  45.     #ifndef ONLINE_JUDGE
  46. //        freopen("in.txt", "r", stdin);
  47. //        freopen("n.txt", "w", stdout);
  48.     #endif
  49.     Love();
  50.     return 0;
  51. }

No comments:

Post a Comment