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

53 篇文章 0 订阅

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 <stdio.h>
#include <vector>
#include <algorithm>
#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值