CF Harbour.Space D

CF Harbour.Space Scholarship Contest 2021-2022 D

[link](Problem - D - Codeforces)

题意

给定一个字符串,从前往后一个一个枚举,对于每一个字母可以进行两种操作选取这个和不选这个并删除前一个(如果前面没有也可以成立),问是否可以通过合法的操作将给定的字符串变成提问的字符串。

题解

对于原串str中选取的字母之间必须相差为0或2的倍数,从前往后考虑,当选完要选的最后一个字母后剩下的不知道是否成立,因此从后往前考虑较好,从后往前每一个如果对就要,否则就跳2,因此如果存在合理的方案,那么最后一个一定是偶数的跳过去,或者等效替代前面的,一定要选。

例如:

axxbxxcxc 偶数跳

axxbxcxxc 等效替代

*Code

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath> 
#include <stack>
#include <iomanip> 
#define x first
#define y second
#define eps 1e-7
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 30010, INF = 0x3f3f3f3f, P = 131, mod = 1e9 + 7;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int n, m;
int a[N], s1[N], s2[N];
int main () {
//	cin.tie(nullptr)->sync_with_stdio(false);
	int T;
	cin >> T;
	while (T --) {
		string str, t;
		cin >> str >> t;
		reverse(str.begin(), str.end()), reverse(t.begin(), t.end());
		int n = str.size(), m = t.size();
		bool ok = false; 
		for (int i = 0, j = 0; i < n; i ++ ) {
			while (str[i] == t[j] && i < n) {
				i ++ , j ++;
			}
			i ++;
			if (j == m) {
				ok = true;
				break;
			}
		}
		cout << (ok ? "YES" : "NO") << endl;
	}
	 return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值