zoukankan      html  css  js  c++  java
  • Codeforces Round #321 (Div. 2) A. Kefa and First Steps 水题

    A. Kefa and First Steps

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/580/problem/A

    Description

    Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makesai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.

    Help Kefa cope with this task!

    Input

    The first line contains integer n (1 ≤ n ≤ 105).

    The second line contains n integers a1,  a2,  ...,  an (1 ≤ ai ≤ 109).

    Output

    Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.

    Sample Input

    6
    2 2 1 3 4 1

    Sample Output

    3

    HINT

    题意

    求最长非降子序列

    题解:

    暴力扫一遍就好了……

    代码:

    //qscqesze
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <bitset>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::ssecondnc_with_stdio(0);cin.tie(0)
    #define maxn 100006
    #define mod 1000000007
    #define eps 1e-9
    #define PI acos(-1)
    const double EP  = 1E-10 ;
    int Num;
    //const int inf=0first7fffffff;
    const ll inf=999999999;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //*************************************************************************************
    
    int a[maxn];
    int ans = 0;
    int Ans = 0;
    int main()
    {
        int n=read();
        for(int i=0;i<n;i++)
        {
            a[i]=read();
        }
        for(int i=1;i<n;i++)
        {
            if(a[i]>=a[i-1])
            {
                ans++;
                Ans=max(Ans,ans);
            }
            else
                ans=0;
        }
        printf("%d
    ",Ans+1);
    }
  • 相关阅读:
    深入PHP内核之全局变量
    关于PHP中的opcode
    深入PHP内核之opcode handler
    virtual memory exhausted: Cannot allocate memory
    Nginx配置error_page 404错误页面
    PHP 与 UTF-8
    define() vs const 该如何选择?
    CentOS安装配置Samba
    当···时发生了什么?
    PHP中curl的使用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4831478.html
Copyright © 2011-2022 走看看