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;
}
时间: 2024-10-20 06:29:17

Codeforces Round #425 B的相关文章

Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组

Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to h

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

n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n

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

题目链接:http://codeforces.com/problemset/problem/832/B 题意:给定一些小写字符(定义为好字符,除这些好字符外的其他小写字符都是坏字符).和字符串S,S里面除了小写字母以外还有?字符,?可以用任何的好字符替代:*字符,*只可以用坏字符串和 空替代,然后给出n个字符串去匹配S字符,问是否能成功. 题解:QAQ,这道题写的我头发又掉了好多. 设拿来匹配S的字符串为T 字符串要匹配,长度要相同吧.*既然这么强大,可以空,那么T的长度最多比S的长度少1:然后

Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks

It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules

Codeforces Round #425 D

Misha, Grisha and Underground 题意:给一颗树,每个点权值为1,q个询问,每个询问给出a,b,c,3 个点,选择一个点为起点,一个点为终点,形成一条路径,第3个点做为第二条路径的起点,问2条路径上重复区间的点权和的最大值 思路:树链剖分或者LCA,树链剖分映射到数状数组上,没有更新,求出ab ac bc之间的权值和,最长的路径和第二长的路径重复的部分就是答案 AC代码: #include "iostream" #include "string.h&

Codeforces Round #425 (Div.2)

A.Sasha and Sticks 题意:有两个人,每次轮流从n个棒子中抽出k个,直到剩余不足k个棒子.Sasha先抽.如果Sasha抽取的多,则输出YES,否则输出NO. 思路:n/k为奇数时,Sasha获胜. 1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 typedef long long LL; 5 LL n, k; 6 int main() 7 { 8 while (~scanf(&quo

Codeforces Round #425 A

Sasha and Sticks 题意:n根棍子,每次拿走k根,当不足k根的时候不能拿,输,判断先手能否赢 思路:(n/k)&1,直接判断能经行奇数次取木棍还是偶数 AC代码: #include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vecto

【树链剖分】【dfs序】【LCA】【分类讨论】Codeforces Round #425 (Div. 2) D. Misha, Grisha and Underground

一棵树,q次询问,每次给你三个点a b c,让你把它们选做s f t,问你把s到f +1后,询问f到t的和,然后可能的最大值是多少. 最无脑的想法是链剖线段树--但是会TLE. LCT一样无脑,但是少一个log,可以过. 正解是分类讨论, 如果t不在lca(s,f)的子树内,答案是dis(lca(s,f),f). 如果t在lca(s,f)的子树内,并且dep(lca(s,t))>dep(lca(f,t)),答案是dis(lca(s,t),f): 否则答案是dis(lca(f,t),f). #in

Codeforces Round #425 (Div. 2) D. Misha, Grisha and Underground

题意:给出 一颗树,然后q个询问,每个询问给出3个点,让我们自己选择一个起点一个终点,这条路线上的点标记,问第三个点到终点的最多标记点是多少 思路:第三个点到终点的标记点,肯定是第三个点与起点的最近公共祖先到终点的标记点.我们可以求出三个点的的三种最近公共祖先,取深度最大的点K,然后求K到三个点的距离+1 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+10; 4 5 const int DEG=17; 6