CCF Certification Exam-vertex count

Source: Internet
Author: User

Description: Simple question

#include <iostream>using namespacestd;intMain () {intI, J, a[ +], N, Count =0; CIN>>N;  for(i =0; I < n; i++) {cin>>A[i]; }     for(i =1; I < n1; i++)    {        if(a[i-1] <A[i]) {            if(A[i] > a[i +1]) {count++; }                }        Else        {            if(A[i] < A[i +1]) Count++; }} cout<< count<<Endl; return 0;}

Question number: 201604-1
Question Name: Vertex count
Time limit: 1.0s
Memory Limit: 256.0MB
Problem Description: The problem description given n integers represents the sales of a store for a continuous n-day. If sales were to grow before the end of the day, and sales were reduced in the next day, the day would be a fold, in turn, the day would be a fold if the previous sales had decreased and then the sales grew. The rest of the day is not a folding point. For example, the 3rd and 6th days are vertices.

Given n integers a1, a2, ..., an represents sales volume, please calculate how many vertices are in total these days.
In order to reduce ambiguity, the data we have given guarantees that the sales of two consecutive days in this N day are always different, namely Ai-1≠ai. Note that if the two days are not contiguous, the sales volume may be the same. Input format the first line of input contains an integer n.
The second line contains n integers, separated by spaces, representing A1, A2, ..., an. Output format outputs an integer that represents the number of vertices that appear. Sample Input 7
5 4 1 2 3 6 4 Sample Output 2 evaluation use case scale and convention all evaluation cases meet: 1≤n≤1000, the daily sales volume is not more than 10000 non-negative integers.

CCF Certification Exam-vertex count

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.