当前位置:   article > 正文

codeforces 1600E. Array Game (博弈)_alice and bob are playing a game with two unbalanc

alice and bob are playing a game with two unbalanced dice (with 6 sides, num

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?
给出一个数组
两个人可以轮流从数组头部和尾部取数字
满足两人取得的数字是严格递增的
谁取得最后一个数字的时候输出谁
  • 1
  • 2
  • 3
  • 4
  • 5

思路

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

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";
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/280520?site
推荐阅读
相关标签
  

闽ICP备14008679号