zoukankan      html  css  js  c++  java
  • Round #422 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 tas 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 5
    abc
    xaybz
    output
    2
    2 3
    input
    4 10
    abcd
    ebceabazcd
    output
    1
    2
     1 /*
     2 题目的意思是给出两个字符串,可以把第一个字符串任意位置变成任意的字母使他成为
     3 另一个的子串,求最少变的数量和位置
     4 思路:n^2暴力匹配
     5 */
     6 #include <iostream>
     7 #include <vector>
     8 #include <stdio.h>
     9 using namespace std;
    10 
    11 const int INF=0x3f3f3f3f;
    12 char a[1005],b[1005];
    13 
    14 int main(){
    15     int n,m;
    16     scanf("%d%d",&m,&n);
    17     scanf("%s",a);
    18     scanf("%s",b);
    19     int mn=INF;
    20     vector<int>x;
    21     vector<int>ans;
    22 
    23     for(int i=0;i<=n-m;i++){
    24         x.clear();
    25         for(int j=0;j<m;j++){
    26             if(b[i+j]!=a[j]) x.push_back(j+1);
    27         }
    28         if(mn>x.size()){
    29             ans.clear();
    30             mn=x.size();
    31             for(int i=0;i<mn;i++)
    32                 ans.push_back(x[i]);
    33         }
    34     }
    35     printf("%d
    ",mn);
    36     int q=0;
    37     for(int i=0;i<mn;i++){
    38         if(q++) printf(" ");
    39             printf("%d",ans[i]);
    40     }
    41     printf("
    ");
    42     return 0;
    43 }
  • 相关阅读:
    Linux下Java环境安装
    Go语言学习之10 Web开发与Mysql数据库
    Go语言学习之9 网络协议TCP、Redis与聊天室
    Redis入门指南之三(入门)
    Redis入门指南之一(简介)
    Go语言学习之8 goroutine详解、定时器与单元测试
    Redis入门指南之二(安装及配置)
    Go语言学习之7 接口实例、终端文件读写、异常处理
    Go语言学习之6 反射详解
    Go语言学习之5 进阶-排序、链表、二叉树、接口
  • 原文地址:https://www.cnblogs.com/z-712/p/7307848.html
Copyright © 2011-2022 走看看