Gym 100827G number Game (game)

Source: Internet
Author: User

Number Game

Alice and Bob is playing a game on a line of N squares. The line was initially populated with one of the numbers from 1 to N. Alice and Bob take turns removing a single nu Mber from the line, subject to the restriction. A number may only be removed if it isn't bordered by a higher number On either side. When the number was removed, the square that contained it was now empty. The winner is the player of the removes the 1 from the line. Given an initial configuration, who would win, assuming Alice goes first and both of them play optimally?

Input
Input begins with a line with a single integer T, 1≤t≤100, denoting the number of test cases. Each test case is begins with a line with a single integer N, 1≤n≤100, denoting the size of the line. Next is a line with the numbers from 1 to N, space separated, giving the numbers on line
Order from left to right.

Output
For each test case, print the name of the winning player on a single line.

Sample Input

4 4
2 1 3 4
4
1 3 2 4
3
1 3 2
6
2 5 1 6 4 3

Sample Output

Bob
Alice
Bob
Alice

Test instructions: Enter an n, and then give a sequence of 1~n. Two people take turns taking numbers, and when there is no larger number on either side of the number (next to a space), the number can be taken away.

Exercises

Consider that if you want to take 1, you have to take 1 next to the two numbers are taken away, then if 1 next to two number one of which has been taken away, two people must not want to take the remaining one number, so at this time the number of steps have been determined. Alice as the initiator, the advantage is to choose one of two. 1 beside the special consideration, in fact the principle is the same.

Draw a diagram to show the following (slightly abstract):

Attach several sets of data:

8861 5 3 4 2 677 2 4 6 3 1 561 5 3 4 2 653 4 1 5 2BobAlicealice
                  
                   alice
                   Bob 
                             

Code:

#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;Const intN =100005;intA[n];//Spicy Chicken in the nest//Thank you Xiao Hang =.=BOOLmdzz () {intN; scanf ("%d", &N); intpone, PL, PR; PL=0; PR = n+1;  for(inti =1; I <= N; ++i) {scanf ("%d", A +i); if(A[i] = =1) Pone =i; }     for(inti = pone-1; i >1; --i) {if(A[i] < a[i-1]) {PL = i1; Break; } }     for(inti = Pone +1; I < n; ++i) {if(A[i] < a[i+1]) {PR = i+1; Break; } }    intex = (N-PR +1) +(PL); intls = PONE-PL-1;//the middle of the left    intrs = Pr-pone-1;//right middle.    if(n = =1)return true; //if 1 is on the far left or right    if(Pone = =1|| Pone = =N) {if((ex+1) %2==0)return true; }    //1 not on the side.    Else{        BOOLf =false; //You can get the number of the left 1 first.        if(PL = =0) || (ls >1)) {            if((ex+ls+1) %2==0)return true; F=true; }        //You can take the number 1 right.        if(pr = = n+1) || (Rs >1)) {            if((ex+rs+1) %2==0)return true; F=true; }        //1 or so, you don't have to take it all away.        if(!f && n%2==1)return true; }    return false;}intMain () {intT; scanf ("%d", &t);  while(t--) puts (Mdzz ()?"Alice":"Bob"); return 0;}

Gym 100827G number Game (game)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.