• hdu1025 最长上升子序列 (nlogn)


     水,坑。

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int MAXN = 500010;
    struct node
    {
        int x;
        int y;
    }a[MAXN];
    int s[MAXN];
    bool cmp(node t1,node t2)
    {
        return t1.x<t2.x;
    }
    
    int serch(int left, int right, int v)
    {
        int l, r, m;
        l = left, r = right;
        while(l <= r)
        {
            m = (l + r) / 2;
            if(v > s[m] && v < s[m])
                return m;
            else if(v > s[m])
                l = m + 1;
            else r = m - 1;
        }
        return l;
    }
    int main()
    {
        int n, i, j, ff=0;
        while(scanf("%d",&n)!=EOF)
        {
            memset(s, 0, sizeof(s));
            for(i = 1; i <= n; i++)
                scanf("%d%d",&a[i].x,&a[i].y);
            sort(a + 1, a + n + 1, cmp);
            int len = 1;
            s[1] = a[1].y;
            for(i = 2; i <= n; i++)
            {
                int t = serch(1, len, a[i].y);
                if(t > len)
                {
                    len ++;
                    s[len] = a[i].y;
                }
                else s[t]=a[i].y;
            }
            printf("Case %d:
    ", ++ ff);
            if(len==1)
                printf("My king, at most %d road can be built.
    ",len);
            else
                printf("My king, at most %d roads can be built.
    ",len);
            cout<<endl;
        }
    }
  • 相关阅读:
    kmp算法详解
    艾伦.席森.图灵
    gcd详解
    Shortest Prefixes 字典树模板
    Hat's Words 字典树变式
    统计难题 字典树模板
    Phone List 字典树模板
    字典树详解
    Basic Gcd Problem 线性筛
    codeforces 454 D. Little Pony and Harmony Chest(状压dp)
  • 原文地址:https://www.cnblogs.com/sweat123/p/4986039.html
Copyright © 2020-2023  润新知