ZOJ 3809 The Himalayas



The 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 ofN height sampling values Hi. You should determine how many peaks are there. For alli which satisfies 2 <= i <= N - 1, Hi is defined as a peak if and only ifHi-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 containsN 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
这次比赛幸亏有这么一道水题要不然被剔光头………………呜呜,还不是我做的
不过后来直接敲代码,没有编译直接提交,竟然AC了,也是感觉自己有长进的哈哈哈啊哈哈哈哈。
//The 2014 ACM-ICPC Asia  MuDANJIANG Region Firsr Round 
//A - The Himalayas
//ZOJ 3809
//Judge Status Problem ID Language Run Time(ms) Run Memory(KB) User Name 
// Accepted        3809      C++        0           272         小飞哇咔咔 

#include <iostream>
#include <stdio.h>
using namespace std;
int height[52];
int main(int argc, char const *argv[])
{
	int ncase;
	cin >> ncase;
	while(ncase--)
	{
		int len;
		int count = 0;
		cin >> len;
		for (int i = 0; i < len; ++i)
		{
			cin>>height[i];
		}
		if (len <= 2)
		{
			count = 0;
		}
		else for (int i = 1; i < len-1; ++i)
		{
			if (height[i]>=height[i-1]&&height[i]>=height[i+1]	)
			{
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

你可能感兴趣的:(C++,ACM,ZOJ,签到题)