B. Crossword solving
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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
input
4 10
abcd
ebceabazcd
output
1
2

————————————————————————————————

题目的意思是给出两个字符串,可以把第一个字符串任意位置变成任意的字母使他成为

另一个的子串,求最少变的数量和位置

思路:n^2暴力匹配

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
char a[1005],b[1005]; int main()
{
int n,m;
scanf("%d%d",&m,&n);
scanf("%s",a);
scanf("%s",b);
int mn=INF;
vector<int>x;
vector<int>ans; for(int i=0; i<=n-m; i++)
{
x.clear();
for(int j=0;j<m;j++)
{
if(b[i+j]!=a[j])
x.push_back(j+1);
}
if(mn>x.size())
{
ans.clear();
mn=x.size();
for(int i=0;i<mn;i++)
ans.push_back(x[i]);
}
}
printf("%d\n",mn); int q=0;
for(int i=0;i<mn;i++)
{
if(q++)
printf(" ");
printf("%d",ans[i]);
}
printf("\n");
return 0;
}

  

Codeforces822 B. Crossword solving的更多相关文章

  1. Codeforces Round #422 (Div. 2) B. Crossword solving 枚举

    B. Crossword solving     Erelong Leha was bored by calculating of the greatest common divisor of two ...

  2. cf 822B Crossword solving

    B. Crossword solving time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. B - Crossword solving

    Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he ...

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

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

  5. Codeforces Round #422 (Div. 2)

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

  6. CF-822B

    B. Crossword solving time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. 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 ...

  8. ACM团队周赛题解(3)

    940和822两套div.2 老规矩 #define MAXN 1000000+5#define MOD 1000000007#define PI (acos(-1.0))#define EPS 1e ...

  9. 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划

    [BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...

随机推荐

  1. ftp上传文件异常

    ftp一个服务器 如果是22端口 ssh-2.0-openssh_4.3 ,是什么意思? ftp服务用的是20.21端口,客户端添加ftp信息的时候输入的是21端口 ssh服务用的是22端口,应用于远 ...

  2. 简单DP入门四连发

    复习一下一直不太懂的dp. dp博大精深,路还长着呢 第一题;http://acm.hdu.edu.cn/showproblem.php?pid=2084 从下往上就是水题 #include<c ...

  3. javascript 高级程序设计 一

    前言: 作为一个即将毕业.正在实习的大学生,我也默默的进入了开发者的行列.从一开始的c#编码狗到java程序员再到现在的JS开发者,我一直 希望自己可以在这个'万恶'的互联网时代走的更远.但是我还是一 ...

  4. codeforces round#509

    博主水平不高, 只能打完$4$题, QAQ什么时候才能变强啊嘤嘤嘤 订正完6题了,  还想打今天下午的CF , 只能迟十分钟了, 掉分预定 A. Heist 输出 $max - min + n - 1 ...

  5. CButtonST|CUniButton等按钮类的使用

    CButtonST CButtonST类的使用参考链接:http://www.cnblogs.com/lidabo/archive/2012/12/17/2821122.html CCeButtonS ...

  6. day 3:注释,缩进

    本节内容: 1,注释 2,缩进 1,注释: 使用#可以注释单行 # print("hello world") 三个双引号也可以注释多行 """ pri ...

  7. c++智能指针(2)

    追加一个shared_ptr指针 #include <memory> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { ...

  8. autohotkey快捷键

    ;已经基本修复了输入带shift的时候跟输入法中英文切换之间的冲突 SetStoreCapslockMode, off SetKeyDelay, ^CapsLock:: #UseHook ;用这个和下 ...

  9. PHP 写文件的例子

    $contents = "All the content"; $dir = 'c:'; $file_path = $dir . "\\content.txt"; ...

  10. ubuntu下使用fstab挂载硬盘时,属于root,如何把它改为属于一个用户的(如sgjm)

    http://zhidao.baidu.com/link?url=xnakfVD16EtunTSt3wBm153DyqHnXN3FSPO1E_2SpVmM5bmEIwICLA0N6zN85_ioQ3f ...