zoukankan      html  css  js  c++  java
  • CodeForces 702 A Maximum Increase (贪心,高效算法)

    题意:给定 n 个数,问你连续的最长的序列是几个。

    析:从头扫一遍即可。

    代码如下:

    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    using namespace std ;
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f3f;
    const double eps = 1e-8;
    const int maxn = 1e5 + 5;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    int a[maxn];
    
    int main(){
        cin >> n;
        for(int i = 1; i <= n; ++i)  scanf("%d", &a[i]);
        int ans = 1;
        int s = 0, e = 2;
        int cnt = 0;
        a[0] = 0;
        while(e <= n){
            cnt = 1;
            while(e <= n && a[e] > a[e-1]){  ++cnt;  ++e; }
            ans = max(ans, cnt);
            ++e;
        }
    
        cout << ans << endl;
        return 0;
    }
    
  • 相关阅读:
    如何为创建大量实例节省内存?
    4-5
    4-6
    4-4
    4-3
    4-2
    3-11
    4-1
    3-10
    3-8
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5720315.html
Copyright © 2011-2022 走看看