题目描述

Putting two similar strings together will create a very strong power that can quake the earth into parts and the person who did that can be called the Destroyer of the World. In order to stop the Destroyer of the World, WNJXYK decided to check every string in this world to make sure there is no pair of strings are similar. But some strings are too long that WNJXYK cannot judge whether they are similar to others, so he turns to you for help.
Now WNJXYK need you to determine the maximum s, for string A has a substring A’ and string B has a substring B’ whose length are both s and they differ on at most K positions.

输入

The input starts with one line contains exactly one positive integer T which is the number of test cases.
Each test case contains three lines. The first line contains an integer K and each of the following two lines contains a string indicates string A or string B

输出

For each test case, output one line containing “y” where y is the maximum s.

样例输入

3
3
qwertypoi
qwetyrio
0
qqqqq
qqqaqqqq
10
qwertyuiop
asdfghjklzxcvbnm

样例输出

6
4
10

提示

1≤T≤5,1≤len(A),len(b)≤4000,0≤K≤min⁡{len(A),len(B)}
Strings only contain lowercase English letters.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5050;
int k,ans;
char str1[maxn],str2[maxn];
void fun(char str[],char sstr[])
{int len=min(strlen(str),strlen(sstr));int cnt,r;r=-1;cnt=0;for(int l=0; l<len; ++l){while(r+1<len){if(str[r+1]!=sstr[r+1]){if(cnt+1>k){break;}cnt++;}r++;}ans=max(ans,r-l+1);if(str[l]!=sstr[l]){--cnt;}}
}
int main()
{int t;scanf("%d",&t);while(t--){ans=0;scanf("%d",&k);scanf("%s %s",str1,str2);int l=strlen(str1);for(int i=0; i<l; i++){fun(str1+i,str2);}l=strlen(str2);for(int i=0; i<l; i++){fun(str2+i,str1);}printf("%d\n",ans);}return 0;
}

Similar Strings相关推荐

  1. CodeChef - AMSS Similar Strings

    传送门 输入只有一个n,现在构造一个A串,一个B串,有一个规则,如果aaabbbccc,连续的相同字符,那么这个字符串最终会变成abc,删到只剩一个位置,现在构造A串和B串,使他们的最短串相同,比如a ...

  2. 查找两个字符串中相同字符串_使两个字符串相同的最低成本

    查找两个字符串中相同字符串 Problem statement: 问题陈述: Given two strings string1 and string2 find the minimum cost r ...

  3. 如何在Postgresql中使用模糊字符串匹配

    It's a fact - people make typos or simply use alternate spellings on a frequent basis. 这是事实-人们经常打错字或 ...

  4. Codeforces gym 2013-2014 Samara SAU ACM ICPC Quarterfinal Qualification Contest

    题目地址:http://codeforces.com/gym/100247 2014.10.27版 26号训练的题,今天发现A题有更高效的解法,用到了前缀最大值和后缀最大值 A. The Power ...

  5. Cleaning-Data-in-Python

    文章目录 1. Common data problems 1.1 Data type constraints 1.2 Common data types 1.3 Numeric data or ... ...

  6. Regional 做题记录 (50/50)

    写在前面 博主深感自己太弱了QAQ 于是有了一个刷水的想法,Regional的题目还是有很多考查思维的题目,所以这次是乱做50道思考题,可能会顺带做一些水题,这些题的简要题解会写到这篇博文里面,希望能 ...

  7. 【补充】Linux-2.6.22.6 makefiles.txt翻译

    原英文文档的目录为:Documentation\kbuild\makefiles.txt 译者:陈梓归 Linux Kernel Makefiles Linux内核的Makefiles This do ...

  8. linux使用命令重命名_如何在Linux上使用重命名命令

    linux使用命令重命名 Fatmawati Achmad Zaenuri/Shutterstock.comFatmawati Achmad Zaenuri / Shutterstock.com Ge ...

  9. HRBU 2021年暑期训练阶段三Day1

    目录 A - Similar Strings 题目链接: 题意: 做法: B - card card card 题目链接: 题意: 做法: C - String 题目链接: 题意: 做法: D - C ...

最新文章

  1. nginx怎么部署php项目,nginx怎么正确部署前端项目
  2. 【书签】格式化nginx.conf文件的工具
  3. CentOS 安全配置
  4. css的padding
  5. 单引号(')和双引号()
  6. 全球及中国便携式卧式空压机行业前景动态与投资趋势分析报告2022版
  7. Windows下配置Tomcat使用https协议
  8. StringBuffer类和String 类的 equals 和 ==
  9. android 时间控件使用,android 时间控件的使用
  10. 线性表之链式存储结构_单链表相关算法
  11. 自动根据键盘位置调整UITextView的高度
  12. 奇数求和(信息学奥赛一本通-T1065)
  13. DXperienceEval-6.2.4 DXperience for MS Visual Studio 2002 2003 破解
  14. 大数据_Spark_框架简介---Spark工作笔记0001
  15. 理顺 JavaScript (7) - 数字相关问题
  16. PHP读取表格都是精度,php 小数精度问题
  17. JDBC09 CLOB文本大对象
  18. python3小程序代码_我想使用python写一个小程序作为练习,使用的是python3。
  19. 语音识别之——mfcc什么是汉明窗,为什么加汉明窗
  20. 拼音表大全图_【居家乐学】让拼音活起来

热门文章

  1. 高效程序员工作法(一)
  2. 【conda】——新建32位python环境,vscode无法调试
  3. centos定时运行python_CentOS中实现定时执行python脚本的方法
  4. 西米支付:第三方支付的类型
  5. Shell echo命令
  6. 狗屁不通文章生成器写的文章,评分软件赞不绝口
  7. Bootstrap‘s dropdowns require Popper (https://popper.js.org)
  8. php artisan migrate,laravel 5.1下php artisan migrate的使用注意事项总结
  9. 零基础JavaScript入门教程(37)-揭开JS对象的面纱
  10. 【MySQL】MySQL触发器原理与实战(MySQL专栏启动)