zoukankan      html  css  js  c++  java
  • BZOJ 2083 Intelligence test

    用vector,二分。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<vector>
    #define maxn 1005000
    using namespace std;
    int n,a[maxn],t,m,b[maxn];
    vector <int> v[maxn];
    int read()
    {
        char ch;int data=0;
        while (ch<'0' || ch>'9') ch=getchar();
        while (ch>='0' && ch<='9')
        {
            data=data*10+ch-'0';
            ch=getchar();
        }
        return data;
    }
    int find(int x,int y)
    {
        int l=0,r=v[x].size()-1,ans=-1;
        while (l<=r)
        {
            int mid=l+r>>1;
            if (v[x][mid]>y) {ans=v[x][mid];r=mid-1;}
            else l=mid+1;
        }
        return ans;
    }
    void work()
    {
        m=read();int ret=0;
        for (int i=1;i<=m;i++) b[i]=read();
        for (int i=1;i<=m;i++)
        {
            ret=find(b[i],ret);
            if (ret==-1) {printf("NIE
    ");return;}
        }
        printf("TAK
    ");
    }
    int main()
    {
        n=read();
        for (int i=1;i<=n;i++)
        {
            a[i]=read();
            v[a[i]].push_back(i);
        }
        t=read();
        for (int i=1;i<=t;i++)
            work();
        return 0;
    }
  • 相关阅读:
    练习题
    练习
    2.15
    数组
    java聊天工具12.4
    11.13(2)
    11.13
    10.30 作业
    10.23
    面向对象
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/6044161.html
Copyright © 2011-2022 走看看