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. Andriod——手机尺寸相关的概念 +尺寸单位+关于颜色

    手机的尺寸: 屏幕对角线的长度,单位为英寸(2.54cm) 手机的分辨率: 屏幕能显示的像素的数量, 一般用在长方向上数量*宽方向上数量来表达 手机的像素密度: pixels per inch,也称P ...

  2. Android.DebugOnDevices

    真机调试Android http://www.cnblogs.com/junqilian/archive/2012/11/08/2760734.html

  3. gulp ( http://markpop.github.io/2014/09/17/Gulp入门教程 )

    前言 最近流行前端构建工具,苦于之前使用Grunt,代码很难阅读,现在出了Gulp,真是摆脱了痛苦.发现了一篇很好的Gulp英文教程,整理翻译给大家看看. 为什么使用Gulp Gulp基于Node.j ...

  4. 基因组表达分析:如何选择RNA-seq vs. 芯片

    基因组表达分析:如何选择RNA-seq vs. 芯片 发布日期:2017-03-29 10:00 DNA 芯片(上图左侧)由附着在表面的核酸探针组成.首先,从样品中提取 RNA 并转化为互补 DNA( ...

  5. Telnet远程登录

    假设 电脑A Telnet远程登录 电脑B (Windows) 1.电脑B: 关闭防火墙 开启Telnet服务:“我的电脑”-->“管理”-->“服务”-->Telnet开启 2.电 ...

  6. vim中代码自动格式化

    参考资料: https://blog.csdn.net/qachenzude/article/details/25511875 1,gg 跳转到第一行 2,shift+v 转到可视模式 3,shift ...

  7. [JAVA]JAVA章1 数组数据去重

    一 利用HashSet进行去重 //定义一个数组:有几个重复项 int[] testarray = {1,2,33,4,2,3,44,5,222,3}; //利用HashSet对数组数据去重 Set& ...

  8. 【Redis】安装 Redis接口时异常 ,系统ruby版本过低

    场景 操作系统Linux CentOS 7.2,安装Redis接口时,使用命令:gem install redis ,用于系统ruby版本过低,报错“redis requires Ruby versi ...

  9. 【转】PHP实现验证码

    转自http://www.jb51.net/article/40341.htm 新建一个captcha.php: //验证码类class Captcha { private $charset = 'a ...

  10. 744. Find Smallest Letter Greater Than Target

    俩方法都是用二分查找,一个调库,一个自己写而已. 方法一,调库 static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NUL ...