Andy loves playing games. He wants to play a game with his little brother, Bob, using an array, , of distinct integers. The rules are as follows:
- Bob always plays first and the two players move in alternating turns.
- In a single move, a player chooses the maximum element currently present in the array and removes it as well as all the other elements to its right. For example, if , then it becomes after the first move because we remove the maximum element (i.e., ) and all elements to its right (i.e., and ).
- The modifications made to the array during each turn are permanent, so the next player continues the game with the remaining array. The first player who is unable to make a move loses the game.
Andy and Bob play games. Given the initial array for each game, can you find and print the name of the winner on a new line? If Andy wins, print
ANDY
; if Bob wins, print BOB
.
Input Format
The first line contains a single integer denoting (the number of games). The subsequent lines describe each game array over two lines:
- The first line contains a single integer, , denoting the number of elements in .
- The second line contains distinct space-separated integers describing the respective values of for array .
Constraints
- Array contains distinct integers.
For of the maximum score:
- The sum of over all games does not exceed .
For of the maximum score:
- The sum of over all games does not exceed .
Output Format
For each game, print the name of the winner on a new line (i.e., either
BOB
or ANDY
).
Sample Input 0
2
5
5 2 6 3 4
2
3 1
Sample Output 0
ANDY
BOB
Explanation 0
Andy and Bob play the following two games:
- Initially, the array looks like this:
In the first move, Bob removes and all the elements to its right, resulting in :
In the second move, Andy removes and all the elements to its right, resulting in :
At this point, the array is empty and Bob cannot make any more moves. This means Andy wins, so we printANDY
on a new line. - In the first move, Bob removes and all the elements to its right, resulting in . As there are no elements left in the array for Andy to make a move, Bob wins and we print
BOB
on a new line.
Solution:
- #include <bits/stdc++.h>
- #define pb push_back
- using namespace std;
- typedef long long LL;
- const int S = 100003;
- const int MOD = 1e9+7;
- const double pi = 2 * acos (0.0);
- int _Int(){int x; scanf("%d", &x); return x;}
- LL _LLi(){LL x; scanf("%lld", &x); return x;}
- void pruts(){puts("-1");exit(EXIT_SUCCESS);}
- int dirX[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
- int dirY[] = { 0, 1, 0, -1, 1, -1, -1, 1 };
- int rX[] = { 1, 1, 2, 2, -1, -1, -2, -2 };
- int rY[] = { 2, -2, 1, -1, 2, -2, 1, -1 };
- 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 ) );};
- template < class T > T Distance( T x1, T y1, T x2, T y2 ){ return sqrt( ( x1-x2 ) * ( x1-x2 ) + ( y1-y2 ) * ( y1-y2 ) ); };
- 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*x )%m; };
- int sset(int N, int pos){return N=N|(1<<pos);}
- bool check(int N, int pos){return (bool)(N&(1<<pos));}
- int reset(int N, int pos){return N=N&~(1<<pos);}
- /*******************###########################################********************
- ********************## MD. YA-SEEN ARAFAT(ThunderStroke) ##********************
- ********************## CSE, University of Asia Pacific ##********************
- ********************###########################################********************/
- struct data{
- int val, ind;
- }A[ 100000+3 ];
- bool cmp( data p, data q ){
- return p.val > q.val;
- }
- void Love(){
- int t = _Int();
- while( t-- ){
- int n = _Int();
- for( int i = 0; i < n; i++ ){
- A[ i ].val = _Int();
- A[ i ].ind = i;
- }
- sort( A, A+n, cmp );
- int one = 0, last = n;
- for( int i = 0; i < n; i++ ){
- if( last > A[ i ].ind ){
- if( one ) one = 0;
- else one = 1;
- last = A[ i ].ind;
- }
- }
- if( !one )puts( "ANDY" );
- else puts( "BOB" );
- }
- }
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("in.txt", "r", stdin);
- // freopen("n.txt", "w", stdout);
- #endif
- Love();
- return 0;
- }
No comments:
Post a Comment