Number Game
description:
Alice and Bob are playing a game on a line of N squares. The line is initially populated with one of each of the numbers from 1 to N. Alice and Bob take turns removing a single number from the line, subject to the restriction that a number may only be removed if it is not bordered by a higher number on either side. When the number is removed, the square that contained it is now empty. The winner is the player who removes the 1 from the line. Given an initial configuration, who will 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 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 in 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
题意:
给定一个排列,当一个数字相邻两边的数字都比它小的时候可以把这个数字拿走(拿走之后这个位置会变空),两个人轮流拿数字,拿到1的人赢,问两个人都足够聪明,谁会赢,Alice先手。
分三种情况
#include<iostream>
using namespace std;
const int maxn = 10050;
int a[maxn];
int n;
int rt;
int main(){
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
cin>>n;
int lres = 0 ,rres = 0;
int l = 0,r = 0;
for(int i = 1;i <= n;++i) {
cin>>a[i];
if(a[i] == 1) rt = i;
}
if(n == 1)
{
cout<<"Alice"<<endl;continue;
}
int i;
for(i = rt-1;i >= 1;--i){
if(a[i] > a[i+1]) ++l;
else break;
}
while(i > 0 && a[i] < a[i+1]){
lres++;i--;
}
for(i = rt + 1;i <= n;++i)
{
if(a[i] > a[i-1]) r++;
else break;
}
while(i <= n && a[i] < a[i-1])
{
rres++;i++;
}
if(l == 0){
if(r == 1)
{
if((n - 1 - r - rres)%2 == 0) cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
else if((n-1)%2 == 0) cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
else if(r == 0)
{
if(l == 1)
{
if((n - 1 - l - lres)%2 == 0) cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
else if((n-1)%2 == 0)
cout<<"Alice"<<endl;
else
cout<<"Bob"<<endl;
}
else if(l == 1 && r == 1)
{
if((n - l - lres) %2 == 0) cout<<"Alice"<<endl;
else if((n - r - rres)%2 == 0) cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
else
{
if(n&1)
cout<<"Alice"<<endl;
else
cout<<"Bob"<<endl;
}
}
}