zoukankan      html  css  js  c++  java
  • Codeforce466A——贪心——DZY Loves Sequences

    http://codeforces.com/problemset/problem/446/A

    /*
    贪心,开前缀后缀,枚举,每个i
    */
    /************************************************
    * Author        :Powatr
    * Created Time  :2015-8-16 20:03:03
    * File Name     :cf466A.cpp
     ************************************************/
    
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int MAXN = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    int a[MAXN];
    int pre1[MAXN], pre2[MAXN];
    int main(){
        int n;
        while(~scanf("%d", &n)){
            for(int i = 1; i <= n; i++)
                scanf("%d", &a[i]);
            for(int i = 1; i <= n; i++)
                pre1[i] = pre2[i] = 1;
            for(int i = 2; i <= n; i++){
                if(a[i] > a[i-1])
                    pre1[i] = pre1[i-1] + 1;
            }
            for(int i = n - 1; i >= 1; i--){
                if(a[i+1] > a[i]){
                    pre2[i] = pre2[i+1] + 1;
                }
            }
            int ans = 1;
            if(n > 1) ans = max(pre1[n-1] + 1, pre2[2] + 1);
                for(int i = 2; i <= n - 1; i++){
                    if(a[i+1] - a[i-1] >= 2){
                        ans = max(ans, pre1[i-1] + pre2[i+1] + 1);
                    }
                    else {
                        ans = max(ans , pre1[i-1] + 1);
                        ans = max(ans, pre2[i+1] + 1);
                    }
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    LeetCode Notes_#20 Valid Parentheses
    LeetCode Notes_#14 Longest Common Prefix
    牛客21天刷题_day#3
    牛客21天刷题_day#2
    牛客21天刷题_day#1
    WebGL编程指南
    《Redis 设计与实现》
    《女士品茶》
    《Java应用架构设计:模块化模式与OSGi》
    《编译与反编译技术实战》
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4734915.html
Copyright © 2011-2022 走看看