zoukankan      html  css  js  c++  java
  • hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】

    hdu 6197

    题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是。

    题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组的最长不下降子序列的长度l1和最长不上升子序列的长度l2,若l1>=n-k||l2>=n-k,则满足要求。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int INF=0x3f3f3f3f;
    const int maxn=1e5+10;
    int s[maxn],a[maxn],b[maxn];
    int n,k;
    
    int main()
    {
        int T;
        cin>>T;
        while(T--)
        {
            cin>>n>>k;
            for(int i=0;i<n;i++){
                a[i]=b[i]=INF;
            }
            for(int i=0;i<n;i++){
                cin>>s[i];
                *upper_bound(a,a+n,s[i])=s[i];
            }
            for(int i=n-1;i>=0;i--){
                *upper_bound(b,b+n,s[i])=s[i];
            }
            int sz1=lower_bound(a,a+n,INF)-a;//最长不下降
            int sz2=lower_bound(b,b+n,INF)-b;//最长不上升
            if(sz1>=(n-k)||sz2>=(n-k))
                cout<<"A is a magic array."<<endl;
            else
                cout<<"A is not a magic array."<<endl;
        }
        return 0;
    }
  • 相关阅读:
    导出数据到Excel文件
    百度地图
    Web报表-RDLC报表的使用
    web开发经验—MVC 图表Chart
    数据库面试题
    滑块插件jRange的使用
    matplotlib绘图使用数据
    JS面向对象之封装
    如何使用Animate.css插件库
    圣杯布局,双飞翼布局
  • 原文地址:https://www.cnblogs.com/zxhyxiao/p/7515981.html
Copyright © 2011-2022 走看看