D. Let’s Go Hiking time limit per test1 second memory limit per
test256 megabytes inputstandard input outputstandard output On a
weekend, Qingshan suggests that she and her friend Daniel go hiking.
Unfortunately, they are busy high school students, so they can only go
hiking on scratch paper.A permutation p is written from left to right on the paper. First
Qingshan chooses an integer index x (1≤x≤n) and tells it to Daniel.
After that, Daniel chooses another integer index y (1≤y≤n, y≠x).The game progresses turn by turn and as usual, Qingshan moves first.
The rules follow:If it is Qingshan’s turn, Qingshan must change x to such an index x′
that 1≤x′≤n, |x′−x|=1, x′≠y, and px′<px at the same time. If it is
Daniel’s turn, Daniel must change y to such an index y′ that 1≤y′≤n,
|y′−y|=1, y′≠x, and py′>py at the same time. The person who can’t make
her or his move loses, and the other wins. You, as Qingshan’s fan, are
asked to calculate the number of possible x to make Qingshan win in
the case both players play optimally.Input The first line contains a single integer n (2≤n≤105) — the
length of the permutation.The second line contains n distinct integers p1,p2,…,pn (1≤pi≤n) — the
permutation.Output Print the number of possible values of x that Qingshan can
choose to make her win.Examples inputCopy 5 1 2 5 4 3 outputCopy 1 inputCopy 7 1 2 4 6 5 3 7
outputCopy 0 Note In the first test case, Qingshan can only choose x=3
to win, so the answer is 1.In the second test case, if Qingshan will choose x=4, Daniel can
choose y=1. In the first turn (Qingshan’s) Qingshan chooses x′=3 and
changes x to 3. In the second turn (Daniel’s) Daniel chooses y′=2 and
changes y to 2. Qingshan can’t choose x′=2 because y=2 at this time.
Then Qingshan loses.
hhh十天前A的题十天后就忘了 再回想一次做法吧
两人轮流行动,在什么情况下先手可以获胜呢?
1.下降序列的长度应当是奇数
2.等于最大长度的下降序列最多有一个
3.不能被对手直接挡住,也就是一个等腰的“山峰”,从左和从右数应该是一致的。
这样就可以写出来了~
//cyc
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define vector<int> VI
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mst(a) memset(a,0,sizeof a)
using namespace std;
typedef pair<int,int> pii;
const int maxn=1e5+5;
int l[maxn];
int r[maxn];
int p[maxn];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
l[i]=1;
r[i]=1;
cin>>p[i];
}
int maxx=1;
for(int i=2;i<=n;i++){
if(p[i]>p[i-1])l[i]=l[i-1]+1;
// cout<<l[i]<<endl;
maxx=max(maxx,l[i]);
}
for(int i=n-1;i>=1;i--){
if(p[i]>p[i+1])r[i]=r[i+1]+1;
// cout<<r[i]<<endl;
maxx=max(maxx,r[i]);
}
//cout<<maxx<<endl;
int cnt=0;
int pz=0;
for(int i=1;i<=n;i++){
if(l[i]==maxx)cnt++;
else if(r[i]==maxx)cnt++;
if(!pz){
if(l[i]==maxx||r[i]==maxx){
pz=i;
}
}
}
if(cnt==1){
if(maxx%2==1&&l[pz]==r[pz]){
cout<<1<<endl;
}
else cout<<0<<endl;
}
else cout<<0<<endl;
}