codeforces 1600E. Array Game (博弈)

contents:

题意

Alice and Bob are playing a game. They are given an array A of length N. The array consists of integers. They are building a sequence together. In the beginning, the sequence is empty. In one turn a player can remove a number from the left or right side of the array and append it to the sequence. The rule is that the sequence they are building must be strictly increasing. The winner is the player that makes the last move. Alice is playing first. Given the starting array, under the assumption that they both play optimally, who wins the game?
给出一个数组
两个人可以轮流从数组头部和尾部取数字
满足两人取得的数字是严格递增的
谁取得最后一个数字的时候输出谁

思路

一开始是可以任意取的,当然是A选择有利于自己的
相当于A选了之后B没得选
B只能按照A最初规划好的思路去选择
对于数组两端的数字
坑定有一个比较小的数
假设第一个人选择大的数
那么后来的数字永远取不到那个小的数
取到取不到为之
当那个人取了比较小的数,此时B可以取另一个比较大的
数要是B可以赢的话,A就直接取这个B取的数
要是B不能赢的话,B就去取A取数那一头的数
由此可以得出结论,从一开始就两头取数的可能就不存在
只能由A选择一个有利于自己的取数端

AC

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &i : a)
        cin >> i;
    int l = 0, r = n - 1;
    while (l + 1 < n && a[l] < a[l + 1])
        l++;
    while (r - 1 >= 0 && a[r] < a[r - 1])
        r--;
    l++;
    r = n - r;
    (l % 2 || r % 2) ? cout << "Alice" : cout << "Bob";
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

.0-0.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值