codeforces B. Nastya and Door
程序员文章站
2022-06-08 16:01:28
...
题目
题意:
实际上就是问你在~中的山峰有几个。
思路:
我们可以用前缀和的思维记录到了点的时候,总共加上了几个山峰,然后后面查询的时候,就用,最后的时候相减后就是需要的山峰数量了,因为如果头或者尾是峰顶的话,那么其实这个就不算是一个山峰了(题目有说),所以要尾部的要。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
inline void out(int x) {
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
const int maxn = 2e5 + 10;
int a[maxn] = {0}, cnt[maxn] = {0}, cntt[maxn] = {0};
int main() {
int t, n, k;
read(t);
while (t--) {
memset(cnt, 0, sizeof(cnt));
memset(cntt, 0, sizeof(cntt));
read(n), read(k);
for (int i = 1; i <= n; i++) read(a[i]);
for (int i = 2; i <= n - 1; i++) {
if (a[i - 1] < a[i] && a[i] > a[i + 1]) cntt[i]++;
}
for (int i = 1; i <= n; i++) cntt[i] += cntt[i - 1];
int Max = 0, kk = 1;
for (int i = k; i <= n; i++) {
if (cntt[i - 1] - cntt[i - k + 1] > Max) Max = cntt[i - 1] - cntt[i - k + 1], kk = i - k + 1;
}
printf("%d %d\n", Max + 1, kk);
}
return 0;
}
上一篇: 请推荐一个好的joomla邮件群发PHP模块解决方法
下一篇: Yii 操作数据库_MySQL
推荐阅读
-
Codeforces Round #435 (Div. 2)-B. Mahmoud and Ehab and the bipartiteness
-
codeforces 1278 B. A and B
-
Codeforces Round #553 (Div. 2) B. Dima and a Bad XOR(异或+思维)
-
Codeforces Round #246 (Div. 2) ?B. Football Kit_html/css_WEB-ITnose
-
Codeforces Round #261 (Div. 2)B. Pashmak and Flowers(容易)
-
Codeforces Round #266 (Div. 2) B. Wonder Room_html/css_WEB-ITnose
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #650 (Div. 3) B. Even Array
-
Codeforces Round #461 (Div. 2) B. Magic Forest(异或的性质)
-
Codeforces Round 604 B. Beautiful Numbers