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

Subsequence

题目链接

  • 时间:3000ms
  • 内存:262144K

Give a string SSS and NNN string TiT_iTi , determine whether TiT_iTi is a subsequence of SSS.

If ti is subsequence of SSS, print YES,else print NO.

If there is an array {K1,K2,K3,⋯ ,Km}\lbrace K_1, K_2, K_3,\cdots, K_m \rbrace{K1,K2,K3,,Km} so that 1≤K1<K2<K3<⋯<Km≤N1 \le K_1 < K_2 < K_3 < \cdots < K_m \le N1K1<K2<K3<<KmN and Ski=TiS_{k_i} = T_iSki=Ti, (1≤i≤m)(1 \le i \le m)(1im), then TiT_iTi is a subsequence of SSS.

Input

The first line is one string SSS,length(SSS) ≤100000 \le 100000100000

The second line is one positive integer N,N≤100000N,N \le 100000N,N100000

Then next nnn lines,every line is a string TiT_iTi, length(TiT_iTi) ≤1000\le 10001000

Output

Print NNN lines. If the iii-th TiT_iTi is subsequence of SSS, print YES, else print NO.

样例输入
abcdefg
3
abc
adg
cba
样例输出
YES
YES
NO

题目来源:The Preliminary Contest for ICPC China Nanchang National Invitational and International Silk-Road Programming Contest

  • 大意:给出一个字符串S和N个字符串Ti,问这N个字符串是否为S的子串(不一定连续)。

  • 分析:由于N很大,不能暴力。因此可以记录下26个英文字母在主串中出现的位置。设当前Ti中的字符在主串中的最大位置为-1,遍历Ti,对于每一个字符,在主串中找到一个比当前最大位置大的位置:

    若找到了,更新当前最大位置
    否则,说明Ti不是S的子串
    

若一直到最后都可以更新最大位置,说明Ti是S的子串。

AC代码:

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int maxn = 100005;
//字母出现位置邻接表
vector<vector<int> > vst(26);
int st[26];//未匹配的位置的起点
char s[maxn],ti[maxn];
int main()
{
    scanf("%s",s);
    int s_len = strlen(s);
    for(int i = 0; i < s_len; ++i)
        vst[s[i]-'a'].push_back(i);
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < 26; ++j) st[j]=0;
        scanf("%s",ti);
        int t_len = strlen(ti);
        //已匹配的最大位置
        int maxloc=-1;
        int flag=1;
        for(int j = 0; j < t_len; ++j)
        {
            int zm = ti[j]-'a';
            if(st[zm]>=vst[zm].size())
            {
                flag=0;
                break;
            }
            flag=0;
            for(int k = st[zm]; k <vst[zm].size(); ++k)
            {
                if(vst[zm][k]>maxloc)
                {
                    maxloc=vst[zm][k];
                    st[zm]=k+1;
                    flag=1;
                    break;
                }
            }
            if(flag==0)
                break;
        }
        printf("%s\n",flag?"YES":"NO");
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值