The 2022 ICPC Asia Regionals Online Contest (II) J

J:A Game about Increasing Sequences

不是特别会博弈,只能说一下大概意思

Alice and Bob like playing games.

The game is played on a sequence of length n. Alice and Bob take turns performing the operation, with Alice going first.

In each operation, the player can remove an element from the beginning or the end of the sequence.

If this operation is not the first operation of the game, the removed element must be strictly greater than all the previously removed elements.

The player who cannot perform the operation loses.

Please determine who will win the game if both Alice and Bob play the game optimally.

输入格式:

The first line contains a single integers n(1≤n≤10^5),representing the length of the sequence.

The second line contains n integers a1​,a2​,...,an​(1≤ai​≤10^5),representing the sequence.

输出格式:

For each test case, print "Alice" if Alice will win the game, otherwise print "Bob".

输入样例:

3
1 3 2

输出样例:

Bob

代码长度限制

16 KB

时间限制

1000 ms

内存限制

128 MB

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef double db;
const int N=1e5+10;
int a[N],n;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int l=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]>a[i-1])l++;
        else break;
    }
    int r=1;
    for(int i=n-1;i>=1;i--)
    {
        if(a[i]>a[i+1])r++;
        else break;
    }
    if(l%2==0&&r%2==0)
    {
        puts("Bob");
    }
    else
    {
        puts("Alice");
    }


    return 0;
}

 我们首先不考虑首位相同的清空,假设数值大的那一端叫大头,数值小的叫小头

如果大头那端是连续的奇数个,Alice赢

否则,Alice会选择小头那一端,但是两个人再也不会去大头那一端,因为一去,后面那个人就会变成老六,跟着你。所以如果是小头那端是连续的奇数个,Alice赢。否则Bob赢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值