zoukankan      html  css  js  c++  java
  • HZAU 1205 Sequence Number(双指针)

    题目链接:http://acm.hzau.edu.cn/problem.php?id=1205

    【题意】给你一串数,要求你找到两个数a[i],a[j],使得a[i]<=a[j]且j>=i且j-i最大。

    【分析】预处理1~i的最小值,然后从右往左双指针,维护右端点>左端点,如果右端点<1~L的最小值,则移动右端点。

     

    #include <cstdio>
    #include <vector>
    #include <cstring>
    #include <string>
    #include <cstdlib>
    #include <iostream>
    #include <map>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int>pii;
    const int N = 1e5+5;
    const double eps = 1e-8;
    int T,n,w[N],sum[N<<2],p[N<<2],cnt,m,ret[N];
    int k,a[N],mi[N];
    int main() {
        while(~scanf("%d",&n)){
     
            int ans=0;
            mi[0]=1e9+10;
            for(int i=1;i<=n;i++){
                scanf("%d",&a[i]);
                mi[i]=1e9+10;
            }
            for(int i=1;i<=n;i++){
                mi[i]=min(mi[i-1],a[i]);
            }
            for(int l=n,r=n;l>=1;l--){
                if(mi[l]>a[r]){
                    while(a[r]<mi[l]){
                        r--;
                    }
                    ans=max(ans,r-l);
                }
                else {
                    ans=max(ans,r-l);
                }
            }
            printf("%d
    ",ans);
        }
       return 0;
    }
  • 相关阅读:
    mysql的四种隔离
    mysql-事物
    Mysql数据备份
    线程池
    springboot整合log4j2
    springboot项目部署
    数组去重
    倒叙输出算法
    使用LLDB和debugserver对ios程序进行调试
    Linux使用pyinstaller 编译py成可执行程序
  • 原文地址:https://www.cnblogs.com/jianrenfang/p/6754595.html
Copyright © 2011-2022 走看看