[POI2010]TES-Intelligence Test 洛谷3500 二分

Description


One of the tasks in the Byteotian Intelligence Test (BIT) is to cross out numbers from an initial sequence in such a way that leaves as a result certain given sequences.

Byteasar longs to become the IQ Master of Byteotia, but he is no good in this kind of tasks.

But since practice makes perfect, he intends to practise a lot.

So much in fact that he asks you to write a program that will facilitate the training by verifying his answers quickly.

给定一个数串,和m个小数串,问这些小串都是不是大数字串的子序列

Solution


首先考试的时候题目都看错了(汗

用vector记录每个数字在原序列中出现的位置,每次在出现的数字里面二分一个大于当前位置的最小位置就可以了

数据只有100,辣鸡出题人

Code


#include 
#include 
#include 
#define rep(i, st, ed) for (int i = st; i <= ed; i += 1)
#define pb push_back
#define N 1000001
inline int read(){
    char ch = getchar(); int x = 0;
    while (ch < '0' || ch > '9'){
        ch = getchar();
    }
    while (ch <= '9' && ch >= '0'){
        x = (x << 1) + (x << 3) + ch - '0';
        ch = getchar();
    }
    return x;
}
using std:: vector;
vector<int> pos[N];
int main(void){
    int n = read();
    rep(i, 1, n){
        pos[read()].pb(i);
    }
    int T = read();
    while (T --){
        int l = read();
        int now = 0;
        bool flag = true;
        rep(i, 1, l){
            int tmp = read();
            vector<int>:: iterator p = std:: lower_bound(pos[tmp].begin(), pos[tmp].end(), now + 1);
            int tar = p - pos[tmp].begin();
            if (tar == pos[tmp].size()){
                puts("NIE");
                rep(j, i + 1, l){
                    read();
                }
                flag = false;
                break;
            }
//          printf("%d\n", tar);
            now = pos[tmp][tar];
        }
        if (flag){
            puts("TAK");
        }
    }
    return 0;
}

你可能感兴趣的:(c++,暴力)