ICPC_Number Game(博弈)

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;
        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
链接:https://ac.nowcoder.com/acm/contest/59840/F 来源:牛客网 下个学期XCPC有很多场比赛,但是每支队伍被限定每年只能参加一部分的比赛,这让身为队长的 Newbie_QQH犯难了,该如何做赛站选择,于是他找到了你来帮他解决这个问题。 问题是这样的: XCPC一共有N场比赛,每支队伍只能参加K场比赛。 赛站信息包括赛站名字,赛站难度,赛站距离,是否有参赛资格。 赛站名字用字符串表示。 通过对每个赛站的研究,队长对每场比赛都得出了一个难度系数。(不同赛站的难度系数可能相同) 每一场赛站的参赛要求不同,如果没有参赛资格就不能报名参赛。 Newbie_QQH想参加尽可能更简单的比赛,如果比赛的难度系数相同,他会倾向选赛站距离更近的比赛。请你帮他设计程序选择比赛。 输出选择赛站数量和赛站的信息。 如果有多个赛站选择,优先输出难度系数简单,赛站距离更近的比赛,保证不会有两个难度系数和赛站距离都一样的赛站。 输入描述: 第1行输入两个整数N和K,代表比赛数量,参赛限制 第2-N+1行每行输入Si,Ai,Bi,Ci,代表赛站名字,难度,距离,是否有参赛资格(1代表有资格,0代表无资格) 输出描述: 第一行输出参加赛站的数量cnt 接下来cnt行输出赛站信息。 示例1 输入 复制 5 2 icpc_shenyang 100 20 1 icpc_xian 10 20 1 icpc_jinan 10 20 0 icpc_nanjin 20 15 1 icpc_hangzhou 20 18 1 输出 复制 2 icpc_xian 10 20 1 icpc_nanjin 20 15 1用代码表示出来
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值