Codeforces Round #425 (Div. 2)

A

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9;
const int qq = 2e5 + 10;

int main(){
	LL n, k;	cin >> n >> k;
	LL tmp = n / k;
	if(tmp % 2 == 1) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}


B

题意:给出好字符,给出串st,st中'?'可以被好字符替代,‘*’可以被坏字符组成的字符串替代,然后给出q个询问,给出字符ct问是否能使得st等于ct

思路:关键其实就是处理*。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9;
const int qq = 1e5 + 10;
int mp[30];
char st[qq], qt[qq], ct[qq];

int main(){
	scanf("%s", ct);
	int len = strlen(ct);
	for(int i = 0; i < len; ++i) {
		mp[ct[i]] = 1;
	}
	scanf("%s", st);
	int lens = strlen(st);
	int q;	scanf("%d", &q);
	bool isexit = false;
	for(int i = 0; i < lens; ++i) {
		if(st[i] == '*') {
			isexit = true;
			break;
		}
	}
	int lenq = 0;
	if(isexit) {
		for(int i = 0; i < lens; ++i) {
			if(st[i] != '*') {
				qt[lenq++] = st[i];
			}
		}
	}
	while(q--) {
		scanf("%s", ct);
		int lenc = strlen(ct);
		bool f = true;
		if(isexit) {
			if(lens - 1 > lenc) {
				f = false;
			} else if(lens - 1 ==  lenc) {
				for(int i = 0; i < lenc; ++i) {
					if(qt[i] == '?') {
						if(!mp[ct[i]])	f = false;
					} else if(qt[i] != ct[i]) {
						f = false;
					}
				}
			} else {
				int t = lenc - (lens - 1);
				for(int i = 0, j = 0; i < lens && j < lenc; ++i, ++j) {
					if(st[i] == '?') {
						if(!mp[ct[j]])	f = false;
					} else if(st[i] == '*') {
						int c = 0;
						while(c < t) {
							if(mp[ct[j]]) f = false;
							++j, c++;
						}
						--j;
					} else if(st[i] != ct[j]) {
						f = false;
					} 
				}
			}
		} else {
			if(lenc == lens) {
				for(int i = 0; i < lenc; ++i) {
					if(st[i] == '?') {
						if(!mp[ct[i]])	f = false;
					} else if(st[i] != ct[i]) {
						f = false;
					}
				}
			} else {
				f = false;
			}
		}
		if(f)	puts("YES");
		else	puts("NO");
	}
	return 0;
}



大牛的代码就是不一样、

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9;
const int qq = 1e5 + 10, z = 60;
bool good[z];
string goods, pat;
int n;
bool mat(string pat, string s) {
	if(pat.size() != s.size()) {
		return 0;
	}
	for(int i = 0; i < s.size(); ++i) {
		if(pat[i] != '?') {
			if(s[i] != pat[i])	return 0;
		} else {
			if(!good[s[i] - 'a'])	return 0;
		}
	}
	return 1;
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> goods >> pat >> n;
	for(auto c : goods) {
		good[c - 'a'] = 1;
	}
	auto p = pat.find('*');
	string s;
	while(n--) {
		cin >> s;
		if(s.size() < pat.size() - 1) {
			cout << "NO\n";
		} else if(p == string::npos) {
			cout << (mat(pat, s) ? "YES" : "NO") << endl;
		} else {
			bool ok = 1;
			ok &= mat(pat.substr(0, p), s.substr(0, p));
			reverse(pat.begin(), pat.end());
			reverse(s.begin(), s.end());
			p = pat.size() - p - 1;
			ok &= mat(pat.substr(0, p), s.substr(0, p));
			reverse(pat.begin(), pat.end());
			reverse(s.begin(), s.end());
			p = pat.size() - p - 1;
			for(int i = p; i < s.size() - (pat.size() - p - 1); ++i) {
				ok &= !good[s[i] - 'a'];
			}
			cout << (ok ? "YES" : "NO") << endl;
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值