The Himalayas --The 2014 ACM-ICPC Asia Mudanjiang Regional First Round - A
来源:互联网 发布:手机淘宝电脑版网页 编辑:程序博客网 时间:2024/05/18 04:47
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 Nheight 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
291 3 2 4 6 3 2 3 151 2 3 4 5
Sample Output
30
此题可以用很多种做法,最简单直接扫,还有线段树也可以,刚刚在浙大oj上参加的网络赛题目。
代码:
#include <iostream>#include <cstdio>#define MAXN 8850using namespace std;int main(){ int n, m; int a[MAXN] = {0}; scanf("%d", &n); for(int i = 0; i < n; i++) { int ans = 0; scanf("%d", &m); for(int j = 0; j< m; j++) { scanf("%d", &a[j]); } for(int k = 1; k < m - 1; k++) { if(a[k] > a[k-1] && a[k] > a[k+1]) ans++; } printf("%d\n", ans); } return 0;}
- The Himalayas --The 2014 ACM-ICPC Asia Mudanjiang Regional First Round - A
- zoj 3809 The Himalayas 水题 The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round A
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round C
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round J
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round小记
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round B&&zoj3810
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round C ZOj 3811
- zoj 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round C
- zoj 3811 Untrusted Patrol 图论 The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- ZOJ 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- ZOJ 3818 Pretty Poem The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest - A
- 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 【部分题解】
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest - I
- Codeforces Round #263 (Div. 2)-B. Appleman and Card Game
- 031_连续子数组的最大和
- Python手册学习(二):集合
- 关于参加ACM的几个误区
- chapter10 分治法 动态规划 贪心算法
- The Himalayas --The 2014 ACM-ICPC Asia Mudanjiang Regional First Round - A
- 【索引】Rujia Liu's Problems for Beginners
- 洪純彦 石星(兵部尙書)
- android实现省市查询
- 经验:程序员10大职业生存技巧
- Intent的使用
- Valid Palindrome
- Django book 2.0 的中文翻译。
- 【转载】一个合格的程序员应该读过哪些书