原题传送门:Petya and Countryside
由于数据相对比较小,而且是一维情况,因此完全可以暴力枚举。
这题唯一需要注意的要点就是搜索的起始点、终止点,以及去重的过程,其它的便无需赘述。
上代码:
#include <iostream>
using namespace std;
int main()
{
int n;
int height[1001], maxsize = 1;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> height[i];
}
for (int i = 1; i <= n; i++)
{
int count = 1;
int j = i;
while (height[j-1] <= height[j] && j >= 2) // 注意范围
{
count++;
j--;
} // 左端计数
j = i;
while (height[j+1] <= height[j] && j <= n-1) // 注意范围
{
count++;
j++;
} // 右端计数
maxsize = max(maxsize, count);
}
cout << maxsize;
return 0;
}
p.s. 这题居然有80个测试点(