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 }
  • 相关阅读:
    操作数据库系统(OLTP)和联机分析处理系统(OLAP)的区别
    BI笔记-SSAS部署的几种方式及部署后的SSAS刷新
    概念-数据仓库与元数据
    零基础学Python 3之环境准备
    OFBiz进阶之HelloWorld(五)创建新实体
    OFBIZ bug_create-component ERROR
    OFBIZ bug_ControlServlet.java:233:ERROR
    OFBiz进阶之HelloWorld(三)CRUD操作
    OFBiz进阶之HelloWorld(二)创建热部署模块
    OFBIZ bug_ControlServlet.java:239:ERROR
  • 原文地址:https://www.cnblogs.com/z-712/p/7307848.html
Copyright © 2011-2022 走看看