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的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...
随机推荐
- andorid EditView
<?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android=" ...
- Get、Post 提交的乱码问题
1.问题 在spring mvc开发的时候出现乱码问题: 2.解决方案 (1)Get提交:tomcat容器接收的造成的乱码问题,修改server.xml文件: (2)Post提交:在web.xml中配 ...
- POJ3621或洛谷2868 [USACO07DEC]观光奶牛Sightseeing Cows
一道\(0/1\)分数规划+负环 POJ原题链接 洛谷原题链接 显然是\(0/1\)分数规划问题. 二分答案,设二分值为\(mid\). 然后对二分进行判断,我们建立新图,没有点权,设当前有向边为\( ...
- python提取百度经验<标题,发布时间,平均流量,总流量,具体的链接>
之前想研究下怎么抓网页数据.然后就有了下面的练习了. 如有BUG.也纯属正常. 只是练习.请勿投入产品使用. #!/usr/bin/python # -*- coding: utf-8 -*- #Fi ...
- 强大的easygrid V7 ,可联系作者
增加历史记录事件 修改bug 修改风格 演示绑定表达式 下载demo
- flask 中文编码解码
process.append("中文") print(process) # return Response(json.dumps(process), mimetype='appli ...
- robot framework 中should be true 与should contain 的区别
should be true 是否等于:判断是否should contain 是否包含 a是否包含b
- java的nio例子
package main; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.Inet ...
- 【搜索】 Prime Path
#include<cstdio> #include<cstring> #include<cmath> #include<queue> #include& ...
- Servlet----监听器
监听器的使用: 作用: 监听作用域对象request.session.application的创建.销毁和内容的改变 使用: 创建一个 ...