Number of days in Luogu P1567 and Luogu p1567

Source: Internet
Author: User

Number of days in Luogu P1567 and Luogu p1567
Background

Statistical days

Description

In the hot summer, KC is very uncomfortable. He would rather endure the cold Arctic than the summer in Xiamen. Recently, he began to study weather changes. He hopes to use the research results to predict the future weather.

He collected the highest temperature data for N (1 <= N <= 10 ^ 7) consecutive days.

Now he wants to know the maximum number of consecutive days that the maximum temperature has been rising.

Input/Output Format

Input Format:

 

* Row 1: an integer N. 1 <= N <= 10 ^ 7

* Row 2: an integer separated by N spaces, indicating the maximum temperature for N consecutive days. 0 <= maximum temperature <= 10 ^ 9.

 

Output Format:

 

* Row 1: an integer that indicates the maximum number of consecutive days that the maximum temperature has been rising.

 

Input and Output sample input sample #1: Copy
101 2 3 2 4 5 6 8 5 9
Output example #1: Copy
5
Description

Time limit 1 s memory limit 128 MB

 

 

Xjb simulation ..

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAXN=1e7+10;inline int read(){    char c=getchar();int flag=1,x=0;    while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}    while(c>='0'&&c<='9')x=x*10+c-48,c=getchar();return x*flag;}int n;int a[MAXN];int main(){    n=read();    for(int i=1;i<=n;i++)a[i]=read();a[0]=0x7ffff;    int now=0,mx=0;    for(int i=1;i<=n;i++)    {        if(a[i]>=a[i-1])now++,mx=max(now+1,mx);        else now=0;    }    printf("%d",mx);    return 0;}

  

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.