B - Crossword solving

Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It‘s well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren‘t you?

Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found in t as a substring. All the changes should be the following: Leha chooses one position in the string s and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear in t="aabrbb" as a substring.

Guaranteed that the length of the string s doesn‘t exceed the length of the string t. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found in t as a substring. The symbol "?" should be considered equal to any other symbol.

Input

The first line contains two integers n and m (1?≤?n?≤?m?≤?1000) — the length of the string s and the length of the string t correspondingly.

The second line contains n lowercase English letters — string s.

The third line contains m lowercase English letters — string t.

Output

In the first line print single integer k — the minimal number of symbols that need to be replaced.

In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.

Examples

Input

3 5abcxaybz

Output

22 3 

Input

4 10abcdebceabazcd

Output

12 
 1 #include<bits/stdc++.h>
 2 using namespace  std;
 3
 4 int main() {
 5     int a,b,count;
 6     int ans = 0;
 7     int yy[1005],re[1005];
 8     char str1[1005],str2[1005];
 9     cin>>a>>b;
10     cin>>str1;
11     cin>>str2;
12     queue<int>que;
13     ans = 1009;
14     for(int i = 0; i <= b - a; i++) {
15         count = 0;
16         for(int j = 0; j < a; j++) {
17             if(str1[j] != str2[j+i]) {
18                 yy[count] = j;
19                 count++;
20             }
21         }
22         if(count < ans) {
23             for(int k = 0; k < count; k++) {
24                 re[k] = yy[k];
25             }
26             ans = count;
27         }
28     }
29     cout<<ans<<endl;
30     for(int i = 0; i < ans; i++) {
31         cout<<re[i]+1<<" ";
32     }
33     cout<<endl;
34     return 0;
35 }

原文地址:https://www.cnblogs.com/jj81/p/9123266.html

时间: 2024-07-31 18:15:34

B - Crossword solving的相关文章

#422(div2)B. Crossword solving

题意:给出2个字符串,A,B,A长度严格小于B长度,问改动A多少个字符,能成为B的子串,求最少改动 思路:暴力,2层FOR循环,可用set来存储已B的第i个字符为首需要改动的位置 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 set<int >a[1002]; 5 int main(){ 6 int n,m; 7 cin>>n>>m; 8 string s

Codeforces Round #422 B

Crossword solving 题意:给2个字符串s1,s2,求至少改变s2的多少个字符,才能使s2中包含s1,并输出改变的位置 思路:暴力枚举以每一个位置为开始,和s2匹配,求答案 AC代码: #include<bits/stdc++.h> #include "iostream" #include "string.h" #include "stack" #include "queue" #include &q

codeforces round 422 div2 补题 CF 822 A-F

A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL; const LL N=1,M=1,MOD=1; int main() {//freopen("t.txt","r",stdin); ios::sync_with_stdio(false); LL a,b; scanf("%I64d%I64d",&

Codeforces Round #422 (Div. 2) A-C

A. I'm bored with life 水题 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #include <map> using name

ACM团队周赛题解(3)

940和822两套div.2 老规矩 #define MAXN 1000000+5#define MOD 1000000007#define PI (acos(-1.0))#define EPS 1e-6#define MMT(s,a) memset(s, a, sizeof s)#define GO(i,a,b) for(int i = (a); i < (b); ++i)#define GOE(i,a,b) for(int i = (a); i <= (b); ++i)#define OG

General Problem Solving Techniques [Intermediate-1]~A - Children&#39;s Game

There are lots of number games for children. These games are pretty easy to play but not so easy to make. We will discuss about an interesting game here. Each player will be given N positive integer. (S)He can make a big integer by appending those in

【POJ 3265】Problem Solving

Problem Solving Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1645   Accepted: 675 Description In easier times, Farmer John's cows had no problems. These days, though, they have problems, lots of problems; they have P (1 ≤ P ≤ 300) pro

Volume 1. Elementary Problem Solving :: Sorting/SearchingUva 340,10420,10474,152,299,120,156,400,755

刘汝佳 算法入门 第一版 Uva题目集合(四) Uva 340 #include<stdio.h> #include<string.h> int h[1001][2],g[1001]={0}; int n,m=0,i,j,k,a,b,o; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","

poj 1888 Crossword Answers

Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 Description A crossword puzzle consists of a rectangular grid of black and white squares and two lists of definitions (or descriptions). One list of de