The Preliminary Contest for ICPC China Nanchang National Invitational M题 Subsequence

简介: The Preliminary Contest for ICPC China Nanchang National Invitational M题 Subsequence

题意:给你一个文本字符串P,n个字符串si,然后判断字符串si是不是文本串P的子序列

枚举给个字符最早出现的位置就可以了
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
char s[maxn];
int pos[maxn][30];
int dis[maxn];
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for(int i = n; i >= 1; i--) {
    for(int j = 0; j <= 26; j++) {
      pos[i][j] = pos[i + 1][j];
    }
    pos[i][s[i] - 'a'] = i;
    dis[s[i] - 'a'] = i;
  }
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    int m = strlen(s + 1); 
    int start = dis[s[1] - 'a'];
    if(start == 0) {
      printf("NO\n");
      continue;
    }
    int flag = 1;
    for(int j = 2; j <= m; j++) {
      if(pos[start + 1][s[j] - 'a'] == 0) {
        flag = 0;
        break;
      }
      start = pos[start + 1][s[j] - 'a'];
    }
    if(flag) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  } 
  return 0;
}
相关文章
|
7月前
|
Java
hdu 1164 Eddy's research I
hdu 1164 Eddy's research I
40 0
|
7月前
|
人工智能 Java
hdu 1165 Eddy's research II
hdu 1165 Eddy's research II
43 0
|
机器学习/深度学习 人工智能
The Preliminary Contest for ICPC China Nanchang National Invitational K题 MORE XOR
The Preliminary Contest for ICPC China Nanchang National Invitational K题 MORE XOR
78 0
The Preliminary Contest for ICPC China Nanchang National Invitational H题 Coloring Game
The Preliminary Contest for ICPC China Nanchang National Invitational H题 Coloring Game
96 0
|
机器学习/深度学习
The Preliminary Contest for ICPC China Nanchang National Invitational J题 Distance on the tree
The Preliminary Contest for ICPC China Nanchang National Invitational J题 Distance on the tree
96 0
The Preliminary Contest for ICPC China Nanchang National Invitational A题 PERFECT NUMBER PROBLEM
The Preliminary Contest for ICPC China Nanchang National Invitational A题 PERFECT NUMBER PROBLEM
75 0
|
机器学习/深度学习 人工智能
The Preliminary Contest for ICPC China Nanchang National Invitational I题 Max answer
The Preliminary Contest for ICPC China Nanchang National Invitational I题 Max answer
97 0
German Collegiate Programming Contest 2019 B . Bouldering (最短路)
German Collegiate Programming Contest 2019 B . Bouldering (最短路)
105 0
German Collegiate Programming Contest 2019 B . Bouldering (最短路)
|
机器学习/深度学习 人工智能 BI
The 15th Chinese Northeast Collegiate Programming Contest
The 15th Chinese Northeast Collegiate Programming Contest
146 0
|
人工智能
atcoder AtCoder Beginner Contest 210 D - National Railway(dp)
atcoder AtCoder Beginner Contest 210 D - National Railway(dp)
119 0

热门文章

最新文章