社区讨论
30分求助 玄关
P1317低洼地参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lyskqlm1
- 此快照首次捕获于
- 2024/07/19 18:45 2 年前
- 此快照最后确认于
- 2024/07/19 20:24 2 年前
提供一组下载的数据
输入:
20
0 1 2 3 0 1 3 2 5 4 3 6 3 0 7 5 7 1 4 0
代码输出:
8
标准答案:
6
代码:
CPP// #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;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...