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 }
  • 相关阅读:
    CTFHub-Web-Web前置技能-HTTP协议-响应包源代码详解
    BurpSuite环境安装及设置
    i2 Analyst’s Notebook 9学习笔记之入门、基本概念和数据接口
    Python 练习题:用索引取出LIST中的值
    python 练习题:小明的成绩从去年的72分提升到了今年的85分,请计算小明成绩提升的百分点
    zabbix4.0 本地安装详解及步骤
    CentOS 7 安装 mysql 5.7.27 for zabbix
    win7系统 右击任务栏 资源管理器 弹出菜单“已固定”和“最近”项目不显示故障处理
    CentOS 7 新系统 手动配置网络 简要步骤
    CentOS7 firewalld防火墙 启动 关闭 禁用 添加删除规则等 常用命令
  • 原文地址:https://www.cnblogs.com/z-712/p/7307848.html
Copyright © 2011-2022 走看看