Codeforces Round #422 (Div. 2)
来源:互联网 发布:4d软件下载 编辑:程序博客网 时间:2024/05/17 06:20
http://codeforces.com/contest/822/problem/B
题意:在S1中改变最少次数使得在S2中可以找到S1; 枚举左端点,暴力寻找cnt最小值,复杂度O(n*(m-n+1)) ,n,n<=1000
#include <stdio.h>
#include <iostream>#define MAXN 1000+5
using namespace std;
int main(void)
{
int n,m;
cin >> n >> m;
char s1[MAXN],s2[MAXN];
scanf("%s%s",s1+1,s2+1);
//printf("%s\n%s",s1,s2);
int cnt=n;
int index;
int i,j;
for(i=1;i<=m-n+1;i++)
{
int cnt1=0;
int t=i;
for(j=1;j<=n;j++,t++)
{
if(s2[t]!=s1[j]) cnt1++;
}
if(cnt1<cnt)
{
cnt=cnt1;
index=i;
}
//printf("%d--%d--%d -- ",cnt,index,i);
}
printf("%d\n",cnt);
int t=index;
for(int i=1;i<=n;i++,t++)
{
if(s1[i]!=s2[t])
{
if(cnt==1)
{
printf("%d",i);
cnt--;
}
else
{
printf("%d ",i);
cnt--;
}
}
}
}
阅读全文
0 0
- Codeforces Round #422 (Div. 2)
- Codeforces Round #422 (Div. 2)
- Codeforces Round #422 (Div. 2)
- Codeforces Round #422 (Div. 2) 题解
- Codeforces Round #422 (Div. 2) 解题报告
- Codeforces Round #422 (Div. 2) C
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- Codeforces Round #124 (Div. 2)
- 单链表成环问题
- Docker镜像导出、导入
- mysql 5.7 安装及修改/重置密码
- 从谷歌官方示例谈MVP设计模式
- Android 检测辅助功能是否开启,并调整设置页面
- Codeforces Round #422 (Div. 2)
- Nutz中那些好用的工具类
- 深度学习的认识
- c# 简单执行Post
- rpm包解压时遇到存在依赖项的问题
- 【Python】Struct2 探测工具
- 制作电子相册
- 微信小程序开发系列——4.小程序视图页面基础知识
- 函数