zoukankan      html  css  js  c++  java
  • B. Crossword solving(Round422)

    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

     hint:问你最少换几个字符,可以让s变成t的子串

    大力搞一发

    直接从t的头开始往后匹配判断找最小就好了。。。

     1     #include<iostream>
     2     #include<cstdio>
     3     #include<stdlib.h>
     4     #include<string>
     5     #include<string.h>
     6     #include<vector>
     7     #include<stack>
     8     #include<queue>
     9     #include<map>
    10     #include<cmath>
    11     using namespace std;
    12     #define pi acos(-1.0)
    13     typedef long long ll;
    14 
    15     int key[1050];
    16     int main(){
    17         memset(key, -1, sizeof(key));
    18         int n, m;
    19         cin >> n >> m;
    20         string s, t;
    21         cin >> s >> t;
    22        // cout << s << " " << t << endl;
    23        // int len1 = s.size(), len2 = t.size();
    24         if(n == m){
    25             int cnt = 0;
    26             for(int i = 0; i < n; i++)
    27                 if(s[i] != t[i]){
    28                     key[cnt] = i + 1;
    29                     cnt++;
    30             }
    31             cout << cnt << endl;
    32             for(int i=0; i<cnt; i++){
    33                 cout << key[i] << " ";
    34             }
    35             cout << endl;
    36         }else{
    37             int Min = 1050, cnt = 0;
    38             for(int i=0; i<=m-n; i++){
    39                 cnt = 0;
    40                 for(int j=i; j<i+n; j++){
    41                     if(s[j-i] != t[j]){
    42                         cnt++;
    43                     }
    44                 }
    45                 if(cnt < Min){
    46                     Min = cnt;
    47                     int ind = 0;
    48                     for(int j=i; j<i+n; j++){
    49                         if(s[j-i] != t[j]){
    50                             key[ind++] = j - i + 1;
    51                         }
    52                     }
    53                 }
    54             }
    55             cout << Min << endl;
    56             for(int i=0; i<Min; i++){
    57                 cout << key[i] << " ";
    58             }
    59             cout << endl;
    60         }
    61 
    62         return 0;
    63     }
  • 相关阅读:
    北京Uber优步司机奖励政策(4月1日)
    滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(4月1日)
    成都Uber优步司机奖励政策(3月31日)
    北京Uber优步司机奖励政策(3月31日)
    滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(3月31日)
    uber司机已经激活了,就是还没有上传头
    优步深圳车辆准入标准降啦!6万8年粤车牌!
    开优步认识各色各样的人,人生需要这样的新鲜体验!
    Uber:中国市场两年内不考虑盈利,每年补贴10亿美金
    设置Windows开机自动启动VirtualBox虚拟机系统
  • 原文地址:https://www.cnblogs.com/ledoc/p/7127009.html
Copyright © 2011-2022 走看看