• bzoj 2083: [Poi2010]Intelligence test——vecto+二分


    Description

    霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列。Lyx很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算做很多练习,所以他希望你写一个程序来快速判断他的答案是否正确。

    Input

    第一行为一个整数m(1<=m<=1000000)第二行包括m个用空格分开的整数ai(1<=ai<=1000000),组成了最初的序列,第三行为一个整数n(1<=n<=1000000),表示n个Lyx经过一系列删除得到的序列,每个序列两行,第一行给出长度L(1<=L<=m),然后下一行为L个由空格分开的整数bi(1<=bi<=1000000)。

    Output

    共n行,如果Lyx的序列确实是由最初的序列删除一些数得到,就输出TAK,否则输出NIE。

    Sample Input

    7
    1 5 4 5 7 8 6
    4
    5
    1 5 5 8 6
    3
    2 2 2
    3
    5 7 8
    4
    1 5 7 4

    Sample Output

    TAK
    NIE
    TAK
    NIE
    —————————————————————————————
    这道题我们就直接算每个数离当前位置最近的位置在哪就好了
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<vector>
    using std::lower_bound;
    std::vector<int>::iterator ly;
    const int M=2e6+7;
    int read(){
        int ans=0,f=1,c=getchar();
        while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
        while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
        return ans*f;
    }
    std::vector<int>q[M];
    int n,m,k,p;
    int main(){
        n=read();
        for(int i=1;i<=n;i++) k=read(),q[k].push_back(i);
        m=read();
        for(int i=1;i<=m;i++){
            int now=0;
            bool flag=true;
            k=read();
            for(int j=1;j<=k;j++){
                p=read();
                if(!flag) continue;
                if(q[p].empty()){flag=false; continue;}
                ly=upper_bound(q[p].begin(),q[p].end(),now);
                if(ly==q[p].end()) flag=false;
                else now=*ly;
            }
            if(flag) printf("TAK
    ");
            else printf("NIE
    ");
        }
        return 0;
    } 
    View Code
  • 相关阅读:
    POJ1182
    poj3225 线段树区间操作 (见鬼)
    斜率优化dp(POJ1180 Uva1451)
    POJ2528 线段树的区间操作
    POI2001 Gold mine(二叉排序树 黑书经典)
    POJ3921
    博弈论之威佐夫博弈(转载)
    poj3468(线段树 边覆盖)
    hdu 1166(树状数组 或 线段树)
    压缩软件的改进--- (续先前霍夫曼编码)
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7620233.html
Copyright © 2020-2023  润新知