CF1496D. Let‘s Go Hiking

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值