rt&&数据疑似有误
查看原帖
rt&&数据疑似有误
1413123
Chenyuze24楼主2025/5/21 16:30

rt.rt.

数据有问题吧,第一个数据应该1次就够了。

10
-5 -4 -3 3 0 0 1 2 -4 2

若不对,求调

#include<bits/stdc++.h>
using namespace std;
int n;
long long a[100005];

bool check1() {

    vector<int> pos;
    for (int i = 2; i <= n - 1; i += 2) {
        if ((a[i] - a[i - 1]) * (a[i] - a[i + 1]) < 0) {
            pos.push_back(i);
        }
    }

    if (pos.size() > 2) {
        return false;
    }
    if (pos.size() == 2) {
        int l = pos[0];
        int r = pos[1];
        if (r - l > 2) {
            return false;
        }
        int mid = (l + r) / 2;
        return (a[mid] - a[l]) * (a[mid] - a[r]) > 0;
    }

    return true;
}


int main() {
    while (cin >> n) {
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];

        }

        if (check1() )cout << "Yes" << '\n';
        else {
            cout << "No" << '\n';
        }
    }
    return 0;
}

2025/5/21 16:30
加载中...