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赢。