zoj 3809 The Himalayas 水题 The 2014 ACM-ICPC Asia Mudanjiang Regional First Round

本文探讨了一个算法问题,即通过一系列海拔高度样本值来确定绘画作品中山峰的数量。通过输入一系列不重复的高度值,算法需判断哪些高度可以视为形成山峰的条件。该问题涉及到对相邻高度值的比较,旨在识别出那些高于其前后值的山峰。通过实例分析和代码实现,展示了如何解决此类问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5341

As an artist, Bob usually need to travel around the world. He made a lot of sketch of scenery on his journey. A famous spot he have visited recently is the Himalayas. The Himalayas is a mountain range in South Asia separating the plains of the Indian subcontinent from the Qinghai-Tibet Plateau. The Himalayas include over a hundred mountains exceeding 7,200 meters in elevation.

One day, Bob came up with an strange idea. He wanted to know the number of mountain peaks in his paintings. As his best friend, he turned to you for help. You are given a list of N height sampling values Hi. You should determine how many peaks are there. For all i which satisfies 2 <= i <= N - 1, Hi is defined as a peak if and only if Hi-1 < Hi > Hi+1.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains one integer N (1 <= N <= 50). The next line contains N integers Hi (1 <= Hi <= 8844). It is guaranteed that any two adjacent height sampling values will be different.

Output

For each test case, output the number of peaks.

Sample Input
2
9
1 3 2 4 6 3 2 3 1
5
1 2 3 4 5
Sample Output
3
0

Author: JIANG, Kai
Source: The 2014 ACM-ICPC Asia Mudanjiang Regional First Round


代码:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>

using namespace std;

#define min2(x, y)     min(x, y)
#define max2(x, y)     max(x, y)
#define min3(x, y, z)  min(x, min(y, z))
#define max3(x, y, z)  max3(x, max(y, z))
#define clr(x, y)      memset(x, y, sizeof(x))
#define fr(i,n)        for(int i = 1; i <= n; i++)
#define upfr(i,j,n)    for(int i = j; i <= n; i++)
#define dowfr(i,j,n)   for(int i = n; i >= j; i--)
#define scf(n)         scanf("%d", &n)
#define ptf(n)         printf("%d",n)
#define ptfs(s)        printf("%s",s)
#define ptln()         printf("\n")
#define srt(a,n)       sort(a,n)
#define LL long long
#define pi acos(-1.0)
#define inf 1 << 31-1
#define eps 0.00001
#define maxn 55

int arr[maxn];
int main()
{
    //freopen("D:\\ACM Contest\\2014 ACM\\The 2014 ACM-ICPC Asia Mudanjiang Regional First Round\\in.txt","r",stdin);
    int t;
    scf(t);
    while(t--)
    {
        clr(arr,0);
        int n;
        scf(n);
        fr(i,n)
            scf(arr[i]);
        int ans = 0;
        fr(i,n-1)
        {
            if(i == 1)
                continue;
            if(arr[i] > arr[i-1] && arr[i] > arr[i+1])
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值