码迷,mamicode.com
首页 > 其他好文 > 详细

[ACM] zoj 3809 The Himalayas (2014 ACMICPC Regional 牡丹江站网络赛 A题)

时间:2014-09-09 12:48:18      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   io   ar   for   2014   art   sp   

he Himalayas

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 <iostream>
#include <algorithm>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
#include <cmath>
#include <string.h>
using namespace std;
int n;
int h[52];

int main()
{
    int t;cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>h[i];
        int cnt=0;
        for(int i=2;i<=n-1;i++)
            if(h[i-1]<h[i]&&h[i]>h[i+1])
            {
                cnt++,i++;
            }
        cout<<cnt<<endl;
    }
    return 0;
}


[ACM] zoj 3809 The Himalayas (2014 ACMICPC Regional 牡丹江站网络赛 A题)

标签:style   color   os   io   ar   for   2014   art   sp   

原文地址:http://blog.csdn.net/sr_19930829/article/details/39151633

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!