cf 822B 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 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.
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.
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*m复杂度
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define lowbit(x) x&(-x)
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
const int inf=0x3f3f3f3f;
int main()
{
int n,m,maxn=,c=,id;
string s,t;
cin>>n>>m>>s>>t;
for(int i=;i<=m-n;i++)
{
c=;
for(int j=;j<n;j++)
{
if(t[i+j]!=s[j]) c++;//每次循环判断最少不匹配的个数。
}
if(c<maxn)
{
maxn=c;
id=i;
}
}
if(maxn==) printf("0\n"),;
else printf("%d\n",maxn);
for(int i=;i<n;i++)
{
if(t[id+i]!=s[i])
printf("%d ",i+);
}
return ;
}
cf 822B Crossword solving的更多相关文章
- Codeforces822 B. Crossword solving
B. Crossword solving time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #422 (Div. 2) B. Crossword solving 枚举
B. Crossword solving Erelong Leha was bored by calculating of the greatest common divisor of two ...
- 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 div2 补题 CF 822 A-F
A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL ...
- 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 ...
- ACM团队周赛题解(3)
940和822两套div.2 老规矩 #define MAXN 1000000+5#define MOD 1000000007#define PI (acos(-1.0))#define EPS 1e ...
- Edu Cf Round 105 (Div. 2) B. Berland Crossword 1.读懂题, 2. 思维
一. 原题链接 https://codeforces.com/contest/1494/problem/B 二. 题意 + 题解: 没看懂题目, 懵了好久, 先狡辩一下当时误解的句子, 英语是硬伤 ...
随机推荐
- 尼克的任务 dp 洛谷1280
蒟蒻表示老久没看过dp题目了,,挺水的一道dp题目都没想出来,,, 首先设dp[i]表示从开始到i时间的最大空闲时间,用vector to[x] 表示从x点开始的任务结束时间,cnt[x]表示从x开始 ...
- 关于多线程lock-free代码
首先要理解JVM内存模型,可以参考我之前的文章. 然后C++里面其实有一样的指令排序的问题.虽然C++11里面针对happens-before规则做了一些语义上面的支持.但是普通C/C++没有做这些支 ...
- 11g v$wait_chains 与 hanganalyze
11g之后,通过v$wait_chains视图诊断数据库hang和Contention 11g之前,通常我们数据库hang住了之后,我们会对数据库做hang analyze来进行分析,在11g之后 ...
- server用JDBC对mysql数据库进行操作
1:获取数据库连接 Connection connection=getConnection(); 2:准备SQL语句 3:调用Connection的creatStatement()方法获取Statem ...
- POJ 1012 Joseph(打表题)
题意:约瑟夫环的变形.要求寻找到一个杀人循环节m使后半节的坏人先被所有杀光. 直接链表模拟出结果,再打表即可: 代码:(凝视的是打表码) #include<iostream> #inclu ...
- Java数组与栈内存、堆内存
package ch4; /** * Created by Jiqing on 2016/11/9. */ public class ArrayInRam { public static void m ...
- Dictionary subtraction
Finding the words from the book that are not in the word list from words.txt is a problem you might ...
- CentOS6.8下完全干净卸载mysql
来源整理于 https://www.cnblogs.com/wanghuaijun/p/6398240.html 虚拟机CentOS6.8下 先执行命令查看目录是否存在mysql 文件夹: cd ...
- 逻辑学总结x
逻辑学是研究事实联系: 肯定.否定: 条件 结论: 联系 规则: 的学问.
- webpack入门与笔记
为什要使用WebPack 现今的很多网页其实可以看做是功能丰富的应用,它们拥有着复杂的JavaScript代码和一大堆依赖包.为了简化开发的复杂度,前端社区涌现出了很多好的实践方法 模块化,让我们可以 ...