赞
踩
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选择一个有利于自己的取数端
#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"; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。