Logo FiraCode 的博客

博客

CF822B题解

...
FiraCode
2025-12-01 12:55:19
什么意思呢

本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2022-05-18 20:41:25

题解思路:

枚举 $t$ 的每一个字母作为开头,然后再和 $s$ 比较,记录一下哪里不一样就要改,最后对这些修改的序列取长度最小的就可以了,长度一样的话,随便一个就可以了。

AC Code

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
int n , m;
string a , b;
int main(){
	\/\/freopen ("temp.in" , "r" , stdin);
	scanf ("%d%d" , &n , &m);
	cin >> a >> b;
	vector <int> ans(114514 , 1);\/\/因为要取min,所以先把长度设成很大的值。
	for (int i = 0; i < m - n + 1; ++ i) {\/\/枚举每一个t里的字母
		vector <int> temp;
		for (int j = 0; j < n; ++ j) 
			if (a[j] != b[i + j]) \/\/只要不一样就要是 ?
				temp.push_back (j);\/\/那么操作就加上j
		if (temp.size() < ans.size()) \/\/更新答案
			ans = temp;
	}
	printf ("%d\n" , ans.size());
	for (int i = 0; i < ans.size(); ++ i)\/\/输出
		printf ("%d " , ans[i] + 1);
	puts("");
	return 0;
}

评论

暂无评论

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。