30分求助 玄关
查看原帖
30分求助 玄关
1041365
Sirius6699楼主2024/7/19 18:43

提供一组下载的数据

输入:

20

0 1 2 3 0 1 3 2 5 4 3 6 3 0 7 5 7 1 4 0

代码输出:

8

标准答案:

6

代码:

// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define coutdouble(a, b) cout << fixed << setprecision(a) << (b)
#define ll long long
#define endl '\n'

using namespace std;

const int N = 10000 + 5;
const int INF = 0x3f3f3f;
const int INFS = -0x3f3f3f;

int n;
int a[N];
int ans = 0;

bool water(int x)
{
    for (int i = x; i <= n - 1; i++)
    {
        if (a[i] > 0) return true;
    }
    return false;
}

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

    for (int i = 2; i <= n - 2; i++)
    {
        if (a[i] < a[i - 1] && water(i)) ans++;
    }

    cout << ans << endl;
}

signed main()
{
    // freopen("../in_out/in.txt", "r", stdin);
    // freopen("../in_out/out.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);  // 关闭同步流

    int t = 1;
    // cin>>t;
    while (t--)
    {
        solve();
    }

    return 0;
}

2024/7/19 18:43
加载中...