The Himalayas(ZOJ)(牡丹江赛区)
2014-09-07 17:52
267 查看
/*The 2014 ACM-ICPC Asia Mudanjiang Regional First Round - A
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 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
*/
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 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
*/
#include<stdio.h> int main() { int str[9000]; int test,n,i; scanf("%d",&test); while(test--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&str[i]); int sum=0; for(i=1;i<n-1;) { if(str[i-1]<str[i]&&str[i]>str[i+1]) { sum+=1; i+=2; } else { i++; } } printf("%d\n",sum); } return 0; }
相关文章推荐
- ZOJ 3809 The Himalayas (2014 ACM/ICPC 牡丹江站 网络预选赛 A 题)
- ZOJ 3811 / 2014 牡丹江赛区网络赛 C. Untrusted Patrol bfs/dfs/并查集
- ZOJ 3819 Average Score (2014年牡丹江赛区现场赛A题)
- ZOJ-3822-Domination【概率dp】【2014牡丹江赛区】
- 2014年ACM牡丹江赛区现场赛K题(ZOJ 3829)
- zoj 3818 Pretty Poem(暴力处理字符串)2014年牡丹江赛区网络赛
- ZOJ 3814 Sawtooth Puzzle (2014年牡丹江赛区网络赛F题)
- ZOJ 3810 A Volcanic Island (2014年牡丹江赛区网络赛B题)
- [ACM] zoj 3809 The Himalayas (2014 ACMICPC Regional 牡丹江站网络赛 A题)
- ZOJ 3818 Pretty Poem (2014年牡丹江赛区网络赛J题)
- ZOJ 3814 / 2014 牡丹江赛区网络赛 F. Sawtooth Puzzle
- ZOJ 3820 2014ACM/ICPC牡丹江赛区B题
- ZOJ3819 ACM-ICPC 2014 亚洲区域赛牡丹江赛区现场赛A题 Average Score 签到题
- ZOJ 3810 A Volcanic Island (2014年牡丹江赛区网络赛B题)
- ZOJ 3811 / 2014 牡丹江赛区网络赛 C. Untrusted Patrol
- ZOJ 3818 The Himalayas (2014 ACM/ICPC 牡丹江站 网络预选赛 J 题)
- ZOJ 3814 Sawtooth Puzzle (2014年牡丹江赛区网络赛F题)
- ZOJ 3665 Yukari's Birthday 第37届ACM/ICPC长春赛区现场赛K题 (水题,枚举,二分)
- zoj 3811||牡丹江网赛 c题 并查集
- zoj 3809 The Himalayas(水题)