zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    75. Sort Colors
    101. Symmetric Tree
    121. Best Time to Buy and Sell Stock
    136. Single Number
    104. Maximum Depth of Binary Tree
    70. Climbing Stairs
    64. Minimum Path Sum
    62. Unique Paths
    css知识点3
    css知识点2
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7620233.html
Copyright © 2011-2022 走看看