CF832B Petya and Exam

思路:

模拟。

实现:

 1 #include <iostream>
 2 using namespace std;
 3
 4 string a, b;
 5 int m, x, y, ok[30];
 6
 7 bool solve()
 8 {
 9     if (y < x - 1) return false;
10     int i = 0, j = 0;
11     for (; i < x; i++, j++)
12     {
13         if (a[i] >= ‘a‘ && a[i] <= ‘z‘)
14         {
15             if (a[i] != b[j]) return false;
16         }
17         else if (a[i] == ‘?‘)
18         {
19             if (!ok[b[j] - ‘a‘]) return false;
20         }
21         else
22         {
23             int tmp = j;
24             for (; j < tmp + y - x + 1; j++)
25             {
26                 if (ok[b[j] - ‘a‘]) return false;
27             }
28             j--;
29         }
30     }
31     return j == y;
32 }
33
34 int main()
35 {
36     string str;
37     cin >> str;
38     int n = str.length();
39     for (int i = 0; i < n; i++)
40     {
41         ok[str[i] - ‘a‘] = 1;
42     }
43     cin >> a >> m;
44     x = a.length();
45     for (int i = 0; i < m; i++)
46     {
47         cin >> b;
48         y = b.length();
49         if (solve()) puts("YES");
50         else puts("NO");
51     }
52     return 0;
53 }
时间: 2024-08-11 05:45:13

CF832B Petya and Exam的相关文章

Round #425 B. Petya and Exam

It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consis

Codeforces_832B: Petya and Exam

题目链接 暴力模拟..好好读题就好了..羡慕英语好的 #include<bits/stdc++.h> using namespace std; typedef long long LL; bool vis[150]; string t; string p,p1; int q; bool ok(string t) { if(t.length()<p1.length()) return false; else { int l=1; //在i指针遇到'*'前,l无具体意义,只为抵消-1的影响:

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 B

Petya and Exam 题意:定义n个字符(小写字母)是好的,其余小写字母都是坏的,给一个字符s串含有"?"表示"?"可以替换成任意好的字符,含有最多一个"*"表示"*"可以替换成任意长度的由坏的字符组成的字符串,给q个询问,每个询问有一个小写字母组成的字符串,询问字符串经过替换后能否与查询的串一样 思路:xjb模拟,题意真jb迷 AC代码: #include "iostream" #include

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 #610 (Div. 2) 题解

Temporarily unavailable K for the Price of One (Hard Version) Petya and Exam Temporarily unavailable \[ Time Limit: 1 s\quad Memory Limit: 256 MB \] 直接计算出 \([c-r, c+r]\) 在 \([a, b]\) 中的范围有多大,然后减掉就可以了. view #include <map> #include <set> #includ

Codeforces Round #610 (Div. 2) a/b/c

题目 传送门 A Temporarily unavailable   standard input/output 1 s, 256 MB  给一个线段ab, 问除去 c点圆心半径r覆盖的 线段多长,如果圆在线段外 直接输出 ab 长度就行, 若在线段内 则输出cout << max(b-a-max((min(c+r,b)-max(a,c-r)),0), 0) ,迷糊的话纸上画下大概就能明白.B1 K for the Price of One (Easy Version) , B2 K for

UVA 11637 - Garbage Remembering Exam(组合概率)

UVA 11637 - Garbage Remembering Exam 题目链接 题意:大概意思是,有n个单词,分别打乱放在一个环形的,一个非环形里面,环形的两个单词距离为顺时针逆时针的最小值,非环形的就是位置的差的绝对值,如果有一对单词,在两个里面的距离都是不大于k,那么这单词为无效单词,问平均会出现多少个无效单词 思路:组合概率,假设在非环形形成了一个随机序列,那么我们给它标号1-n,如果我们能分别算出1-n的有效概率,那么就等于算出了无效概率,那么有效概率等于和它距离大于k的那些位置的所

【OCM】Exam Souvenir 20140707

[OCM考场合影留念] 经过两天的奋战,又一波恩墨OCM战队的顶尖高手们,凭借百分百的发挥完美收官,到此画上了完美的句号. 传承了霸气的手势!Well done! [请访问此 http://www.dbstyle.net/?p=979页面获得更加丰富的内容] [OCM]Exam Souvenir 20140707,布布扣,bubuko.com