zoukankan      html  css  js  c++  java
  • HDU 6197 array array array nlogn求最长子序列 思维

      题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6197

      题目描述: 给一个长度为N的串, 问你能不能去掉K个数成为单调的串

      解题思路: 很明显的求最长上升或者下降子序列的题, 但是N <= 1e6 , 而且我们只要长度, 所以我们就用nlogn 来求......

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <iterator>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <deque>
    #include <map>
    #include <set>
    #include <queue>
    #define lson l, m, rt<<1
    #define rson m+1, r, rt<<1|1
    #define mem0(a) memset(a,0,sizeof(a))
    #define mem1(a) memset(a,-1,sizeof(a))
    #define sca(x) scanf("%d",&x)
    #define de printf("=======
    ")
    typedef long long ll;
    using namespace std;
    
    const int maxn = 1e5+100;
    int a[maxn];
    int b[maxn];
    int ans[maxn];
    
    int main() {
        int t;
        sca(t);
        while( t-- ) {
            int n, k;
            scanf( "%d%d", &n, &k );
            for( int i = 0; i < n; i++ ) {
                scanf( "%d", a+i );
                b[n-i-1] = a[i];
            }
            ans[0] = a[0];
            int cnt = 0;
            for( int i = 1; i < n; i++ ) {
                if( a[i] >= ans[cnt] ) {
                    ans[++cnt] = a[i];
                }
                else {
                    *(upper_bound(ans, ans+cnt, a[i] )) = a[i];
                }
            }
            int ans1 = cnt+1;
            cnt = 0;
            for( int i = 1; i < n; i++ ) {
                if( b[i] >= ans[cnt] ) {
                    ans[++cnt] = b[i];
                }
                else {
                    *(upper_bound(ans, ans+cnt, b[i] )) = b[i];
                }
            }
            int ans2 = cnt+1;
            if( max(ans1, ans2) + k >= n ) {
                printf( "A is a magic array.
    " );
            }
            else {
                printf( "A is not a magic array.
    " );
            }
        }
        return 0;
    }
    View Code

      思考: 这个题以前必然做过啊.....印象非常深, 所以感觉还好........

  • 相关阅读:
    APNS推送通知消息负载内容和本地格式字符串
    TCP/IP协议基础(转)
    IOS学习笔记—苹果推送机制APNs
    IOS 基于APNS消息推送原理与实现(JAVA后台)--转
    IOS私有API的使用(转)
    iOS js与objective-c的交互(转)
    多线程二(GCD)代码笔记
    GCD (Grand Central Dispatch) 笔记
    QTextCodec中的setCodecForTr等终于消失了 (Qt5)
    Qt发布可能遇到的问题
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7503396.html
Copyright © 2011-2022 走看看