Codeforces822 B. Crossword solving
1 second
256 megabytes
standard input
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.
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.
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.
3 5
abc
xaybz
2
2 3
4 10
abcd
ebceabazcd
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的更多相关文章
- Codeforces Round #422 (Div. 2) B. Crossword solving 枚举
B. Crossword solving Erelong Leha was bored by calculating of the greatest common divisor of two ...
- cf 822B Crossword solving
B. Crossword solving time limit per test 1 second memory limit per test 256 megabytes input standard ...
- B - Crossword solving
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he ...
- 【Codeforces Round #422 (Div. 2) B】Crossword solving
[题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...
- Codeforces Round #422 (Div. 2)
Codeforces Round #422 (Div. 2) Table of Contents Codeforces Round #422 (Div. 2)Problem A. I'm bored ...
- CF-822B
B. Crossword solving time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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 ...
- ACM团队周赛题解(3)
940和822两套div.2 老规矩 #define MAXN 1000000+5#define MOD 1000000007#define PI (acos(-1.0))#define EPS 1e ...
- 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划
[BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...
随机推荐
- BZOJ1123或洛谷3469 [POI2008]BLO-Blockade
BZOJ原题链接 洛谷原题链接 若第\(i\)个点不是割点,那么只有这个点单独形成一个连通块,其它点依旧连通,则答案为\(2\times (n-1)\). 若第\(i\)个点是割点,那么去掉这个点相关 ...
- BZOJ 1791: [IOI2008]Island 岛屿 - 基环树
传送门 题解 题意 = 找出无向基环树森林的每颗基环树的直径. 我们首先需要找到每颗基环树的环, 但是因为是无向图,用tarjan找环, 加个手工栈, 我也是看了dalao的博客才知道tarjan找无 ...
- postfix发信提示 Error: too many connectino from
查看提示,很明显是提示连接数过多导致的. 有提示上面的信息,看提示的IP地址是一个网关的地址,使用netstat -ano|grep ':25'|wc -l 看了下,25端口的连接的IP地址,几乎全是 ...
- UI设计教程分享:字体变形—阴阳收缩法
阴阳师中国古代对自然规律发展变化基础因素的描述,是古代美学逻辑思维.推理分析的核心要素,也是描述万物基本要素和成因的概念之一.阴阳代表事物的对立关系,它是自然界的客观规律,是万物运动变化的本源,是人类 ...
- [Robot Framework] Robot Framework里面的变量怎么知道是在哪里定义的?
看变量在哪里定义的:Ctrl+Alt+Space
- 企业官网原型制作分享-Starbucks
星巴克是全球著名的咖啡连锁店,星巴克的产品不单是咖啡,咖啡只是一种载体.而正是通过咖啡这种载体,星巴克把一种独特的格调传送给顾客.咖啡的消费很大程度上是一种感性的文化层次上的消费,文化的沟通需要的就是 ...
- wcf 使用sqlMembership证书认证
.接口 namespace Aretch.WcfService.Services.Interface { [ServiceContract] public interface ICalculator ...
- 【转】VxWorks中高精度实时时钟的实现及C语言汇编混合编程
最近一个项目中需要在VxWorks下使用一个高精度实时时钟,要求精度为1ms,溢 出时间大于5小时.VxWorks提供系统时钟,该时钟在操作系统启动后开始计数,精度为1个tick,可以通过tickGe ...
- java8 forEach Map List[转载]
java8 forEach 在Map和List中的使用 原始的使用 Map<String, Integer> items = new HashMap<>(); items.pu ...
- KM匹配板子
/* gyt Live up to every day */ #include<cstdio> #include<cmath> #include<iostream> ...