Sunday, December 4, 2016

Hackerrank - HourRank 15 - Cats and a Mouse

Two cats named  and  are standing at integral points on the x-axis. Cat  is standing at point  and cat  is standing at point . Both cats run at the same speed, and they want to catch a mouse named  that's hiding at integral point  on the x-axis. Can you determine who will catch the mouse?
You are given  queries in the form of , and . For each query, print the appropriate answer on a new line:
  • If cat  catches the mouse first, print Cat A.
  • If cat  catches the mouse first, print Cat B.
  • If both cats reach the mouse at the same time, print Mouse C as the two cats fight and mouse escapes.
Input Format
The first line contains a single integer, , denoting the number of queries. 
Each of the  subsequent lines contains three space-separated integers describing the respective values of  (cat 's location),  (cat 's location), and  (mouse 's location).
Constraints
Output Format
On a new line for each query, print Cat A if cat  catches the mouse first, Cat B if cat  catches the mouse first, or Mouse C if the mouse escapes.
Sample Input 0
3
1 2 3
1 3 2
2 1 3
Sample Output 0
Cat B
Mouse C
Cat A
Explanation 0
Query 0: The positions of the cats and mouse are shown below:image
Cat  will catch the mouse first, so we print Cat B on a new line.
Query 1: In this query, cats  and  reach mouse  at the exact same time:image
Because the mouse escapes, we print Mouse C on a new line.

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 q = _Int();
  32.     while( q-- ){
  33.         int a = _Int();
  34.         int b = _Int();
  35.         int c = _Int();
  36.         int A = 0, B = 0, C = 0;
  37.         if( abs( a-) > abs( b-) )= 1;
  38.         else if( abs( a-) < abs( b-) )= 1;
  39.         else C = 1;
  40.         if( A )puts( "Cat A" );
  41.         if( B )puts( "Cat B" );
  42.         if( C )puts( "Mouse C" );
  43.     }
  44. }
  45.  
  46. int main(){
  47.     #ifndef ONLINE_JUDGE
  48. //        freopen("in.txt", "r", stdin);
  49. //        freopen("n.txt", "w", stdout);
  50.     #endif
  51.     Love();
  52.     return 0;
  53. }

No comments:

Post a Comment