zoukankan      html  css  js  c++  java
  • The Himalayas (zoj 3809)

    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

     1 #include <iostream>
     2 using namespace std;
     3 int a[1000];
     4 int main()
     5 {
     6     int n;
     7     int t;
     8     cin>>t;
     9     while(t--)
    10     {
    11         cin>>n;
    12         for(int i=0; i<n; i++)
    13             cin>>a[i];
    14         int sum=0;
    15         for(int i=1; i<n-1; i++)
    16         {
    17             if(a[i-1]<a[i]&&a[i]>a[i+1])
    18                 sum++;
    19         }
    20 
    21         cout<<sum<<endl;
    22 
    23     }
    24 
    25     return 0;
    26 }

     

     

  • 相关阅读:
    JDK8 直接定义接口中静态方法
    Spring+Netty+WebSocket实例
    基于Maven,Spring+ActiveMQ实现,贴近实际
    Netty+WebSocket简单实现网页聊天
    ActiveMQ简单入门实例
    WCF 的日志配置
    AutoMapper使用笔记
    博客园现代化建设——AutoMapper
    jqplot formatString 日期格式化列表
    MongoDB实战开发 【零基础学习,附完整Asp.net示例】
  • 原文地址:https://www.cnblogs.com/lengxia/p/4742613.html
Copyright © 2011-2022 走看看