Codeforces Round #425 B

Posted %%%%%

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #425 B相关的知识,希望对你有一定的参考价值。

Petya and Exam

题意:定义n个字符(小写字母)是好的,其余小写字母都是坏的,给一个字符s串含有“?”表示“?”可以替换成任意好的字符,含有最多一个“*”表示“*”可以替换成任意长度的由坏的字符组成的字符串,给q个询问,每个询问有一个小写字母组成的字符串,询问字符串经过替换后能否与查询的串一样

思路:xjb模拟,题意真jb迷

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#define ll long long
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a) memset(a,0,sizeof(a))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lrt (root*2)
#define rrt (root*2+1)
#define len (r-l+1)
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const long long INF = 1e18+1LL;
const int inf = 1e9+1e8;
const int N=1e5+100;
const ll mod=1e9+7;

char s1[N],s2[N],s[N];
int n;
map<char,int> M;
int main(){
    cin>>s1+1>>s2+1;
    int l1=strlen(s1+1), l2=strlen(s2+1);
    for(int i=1; i<=l1; ++i){
        M[s1[i]]=1;
    }
    cin>>n;
    while(n--){
        cin>>s+1;
        int ls=strlen(s+1),i=1,j=0,flag=0; //cout<<ls<<endl;
        for(i=1; i<=l2; ++i){
            if(s2[i]==*){
                for(j=0; j<=ls-l2; ++j){ //cout<<s[j+i]<<"UUUU\n";
                    if(M[s[j+i]]){
                        flag=1;
                        break;
                    }
                }
                --j;
            }
            else{
                if((s2[i]==? && !M[s[i+j]]) || (s2[i]!=? && s2[i]!=s[i+j])){
                    flag=1;
                }
            }
            if(flag){
                cout<<"NO\n";
                break;
            }
        }
        if(!flag && (--i+j)!=ls) cout<<"NO\n";
        else if(!flag) cout<<"YES\n";
    }
    return 0;
}

 

以上是关于Codeforces Round #425 B的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #425 (Div. 2) Problem B Petya and Exam - 暴力

Codeforces Round #425 A

Codeforces Round #425 (Div. 2) B. Petya and Exam(暴力大法好)

Codeforces Round #425 (Div. 2) D 树链剖分 + 树状数组维护区间

Codeforces Round #425 (Div.2)

Codeforces Round #425 (Div. 2) Problem C (Codeforces 832C) Strange Radiation - 二分答案 - 数论