zoukankan      html  css  js  c++  java
  • BestCoder Round #84 Bellovin

    Bellovin

    题意:

    给个中文链接:戳戳戳

    题解:

    这个题其实就是让你求每一位的最长公共子序列,之后输出就好了,求这个有2个算法,一个是n方,另一个nlogn,所以显然是nlogn的算法,其实这就是个模版题。
    但当时做的好坑,比如输出是 2 4 5 2 4 应该输出 1 2 3 1 2 但我当时以为要输出 1 2 3 3 3 脑袋短路了啊 = =

    代码:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    const int INF=0x3f3f3f3f;
    typedef long long ll;
    #define PU puts("");
    #define PI(A) printf("%d
    ",A)
    #define SI(N) scanf("%d",&(N))
    #define SII(N,M) scanf("%d%d",&(N),&(M))
    #define cle(a,val) memset(a,(val),sizeof(a))
    #define rep(i,b) for(int i=0;i<(b);i++)
    #define Rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define reRep(i,a,b) for(int i=(a);i>=(b);i--)
    const double EPS= 1e-9 ;
    
    /*  /////////////////////////     C o d i n g  S p a c e     /////////////////////////  */
    
    const int MAXN=100000 + 9 ;
    
    int dp[MAXN];
    int N;
    int a[MAXN];
    int b[MAXN],cnb;
    int main()
    {
        int o;
        SI(o);
        while(o--)
        {
            SI(N);
            rep(i,N) SI(a[i]);
            int k=N;
            int ans=-1;
            fill(dp,dp+k,INF);
            for (int i=0; i<k; i++)
            {
                *lower_bound(dp,dp+k,a[i])=a[i];
                b[i]=lower_bound(dp,dp+k,a[i])-dp;
                b[i]++;
            }
            rep(i,N) printf("%d%c",b[i],i==N-1?'
    ':' ');
            cle(b,0);
            cnb=0;
        }
        return 0;
    }
  • 相关阅读:
    CentOS7 PXE安装批量安装操作系统
    004_MySQL 主从配置
    CentOS 桥接网卡配置
    玩转 Jupyter Notebook (CentOS)
    搭建专属于自己的Leanote云笔记本
    wetty 安装(web+tty)
    wget命令详解
    linux 下find---xargs以及find--- -exec结合使用
    Linux 交换分区swap
    Linux 时区的修改
  • 原文地址:https://www.cnblogs.com/s1124yy/p/5700169.html
Copyright © 2011-2022 走看看