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 strings="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 tcorrespondingly.

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 5
abc
xaybz
output
2
2 3
 
 
题意:
  给你两个字符串S,T
  问你至少将S串中几个字符改成问号,使得能在T串中找到S
  问号可以和任何字符匹配
 
题解:
  枚举i,j 表示在S串中 i 位置起点, T串中j 位置为起点 是匹配完成的位置
  将必须是问号的pos,数量,记录下来,取个最小的
 
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 1e3+, M = 1e3+,inf = 2e9; int n,m;
char s[N],t[N];
vector<int > G[N];
int main() {
scanf("%d%d",&n,&m);
scanf("%s%s",s+,t+);
int mi = inf;
for(int i = ; i <= m - n + ; ++i) {
for(int j = ; j <= n; ++j) {
if(s[j] != t[i+j-]) {
G[i].push_back(j);
}
}
mi = min(mi,(int)G[i].size());
}
for(int i = ; i <= m - n + ; ++i) {
if(G[i].size() == mi) {
cout<<mi<<endl;
for(int j = ; j < G[i].size(); ++j) {
cout<<G[i][j]<<" ";
}
return ;
}
}
return ;
}

Codeforces Round #422 (Div. 2) B. Crossword solving 枚举的更多相关文章

  1. Codeforces Round #422 (Div. 2)

    Codeforces Round #422 (Div. 2) Table of Contents Codeforces Round #422 (Div. 2)Problem A. I'm bored ...

  2. 【Codeforces Round #422 (Div. 2) B】Crossword solving

    [题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...

  3. 【Codeforces Round #422 (Div. 2) D】My pretty girl Noora

    [题目链接]:http://codeforces.com/contest/822/problem/D [题意] 有n个人参加选美比赛; 要求把这n个人分成若干个相同大小的组; 每个组内的人数是相同的; ...

  4. 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)

    [题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...

  5. 【Codeforces Round #422 (Div. 2) A】I'm bored with life

    [题目链接]:http://codeforces.com/contest/822/problem/A [题意] 让你求a!和b!的gcd min(a,b)<=12 [题解] 哪个小就输出那个数的 ...

  6. Codeforces Round #422 (Div. 2)E. Liar sa+st表+dp

    题意:给你两个串s,p,问你把s分开顺序不变,能不能用最多k段合成p. 题解:dp[i][j]表示s到了前i项,用了j段的最多能合成p的前缀是哪里,那么转移就是两种,\(dp[i+1][j]=dp[i ...

  7. Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP

    E. Liar     The first semester ended. You know, after the end of the first semester the holidays beg ...

  8. Codeforces Round #422 (Div. 2) D. My pretty girl Noora 数学

    D. My pretty girl Noora     In Pavlopolis University where Noora studies it was decided to hold beau ...

  9. Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序,贪心

    C. Hacker, pack your bags!     It's well known that the best way to distract from something is to do ...

随机推荐

  1. DataTable排序

    DataRow[] rows = dt.Select("", "name asc");   DataTable t = dt.Clone();   t.Clea ...

  2. BZOJ 1027 [JSOI2007]合金 ——计算几何

    我们可以把每一种金属拆成一个二维向量,显然第三维可以计算出来,是无关的. 我们只需要考虑前两维的情况,显然可以构成点集所形成的凸包内. 然后我们枚举两两的情况,然后可以发现如果所有的点都在一侧是可以选 ...

  3. HDU 4609 3-idiots ——FFT

    [题目分析] 一堆小木棍,问取出三根能组成三角形的概率是多少. Kuangbin的博客中讲的很详细. 构造一个多项式 ai=i的个数. 然后卷积之后去重. 统计也需要去重. 挺麻烦的一道题. #inc ...

  4. 【bzoj1299】[LLH邀请赛]巧克力棒 博弈+模拟

    Description TBL和X用巧克力棒玩游戏.每次一人可以从盒子里取出若干条巧克力棒,或是将一根取出的巧克力棒吃掉正整数长度.TBL先手两人轮流,无法操作的人输. 他们以最佳策略一共进行了10轮 ...

  5. 酒厂选址(codevs 1507)

    题目描述 Description Abstinence(戒酒)岛的居民们酷爱一种无酒精啤酒.以前这种啤酒都是从波兰进口,但今年居民们想建一个自己的啤酒厂.岛上所有的城市都坐落在海边,并且由一条沿海岸线 ...

  6. linux 管道符号 | ,以及&& ||等等特殊符号笔记

    管道和重导向:“|”.“>”.“>>”.“<” 重导向就是使命令改变它所认定的标准输出.“>”可将结果输出到文件中,该文件原有内容会被删除,“>>”则将结果附 ...

  7. SQLite数据库相关操作

    一.创建数据库 这里创建了note便签数据表,字段有noteId.noteTitle.noteTime.noteInfo );  // TODO Auto-generated constructor ...

  8. SharedPreferences 存储数组+双击退出

    public static void saveApkEnalbleArray(Context context,boolean[] booleanArray) { SharedPreferences p ...

  9. python两个类之间变量和函数的调用

    1.class_a() class_b() 2.class_b使用class_a中的变量和函数 3.变量class_a中:class_a.num=... 函数class_b中:先实例化class_a( ...

  10. stm32f103和s3c2440配置

    stm32                                  s3c2440 外部晶振:  8MHz                                   12MHz