Problem Description
We define the distance of two strings A and B with same length n is
disA,B=∑(i=0  n−1)  |A[i]−B[n−1−i]|
The difference between the two characters is defined as the difference in ASCII.
You should find the maximum length of two non-overlapping substrings in given string S, and the distance between them are less then or equal to m.
 Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integers m : the limit distance of substring.
Then a string S follow.

Limits
T≤100
0≤m≤5000
Each character in the string is lowercase letter, 2≤|S|≤5000
∑|S|≤20000

 
 Output
For each test case output one interge denotes the answer : the maximum length of the substring.
 
Sample Input
1
5
abcdefedcb
 
Sample Output
5

Hint

[0, 4] abcde [5, 9] fedcb The distance between them is abs('a' - 'b') + abs('b' - 'c') + abs('c' - 'd') + abs('d' - 'e') + abs('e' - 'f') = 5

 
给你一个m值,一个字符串,让你在字符串中找两个不重叠的长度相等的字串,两个字符串首对应尾逐项向中心的acsii码差的绝对值之和不能大于m
问这两个相等的字符串最长有多长
 
我们枚举这两个字串的对称中心,对于每个对称中心我们利用双指针进行处理一下就好了
代码如下:
 #include <bits/stdc++.h>

 using namespace std;
const int maxn = +;
char s[maxn];
int m,len;
int ans;
void work (int x,int y)
{
int dis=,l=,r=;//左边的串s[x-l]~s[x-r] 右边的串s[y+l]~s[y+r]
while (y+r<len&&x-r>=){
if (dis+abs(s[x-r]-s[y+r])<=m){
dis+=abs(s[x-r]-s[y+r]);
r++;
ans = max(ans,r-l);
}
else{
dis-=abs(s[x-l]-s[y+l]);
l++;
}
}
}
int main()
{
//freopen("de.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--){
scanf("%d",&m);
scanf("%s",s);
len = strlen(s);
ans = ;
for (int i=;i<len;++i){
work(i-,i+);
work(i,i+);
}
printf("%d\n",ans);
}
return ;
}
 

hdu 6103 Kirinriki (枚举对称中心+双指针)的更多相关文章

  1. HDU 6103 Kirinriki (思维 双指针)

    Kirinriki Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  2. hdu 6103(Kirinriki)

    题目链接:Kirinriki 题目描述: 找两个不重叠的字符串A,B. 使得dis(A,B)<=m;\(dis(A,B)= \sum _{i=0}^{n-1} \left | A_i-B_{n- ...

  3. HDU 6103 Kirinriki(尺取法)

    http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选 ...

  4. 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)

    题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...

  5. HDU - 6103 :Kirinriki(不错的尺取法)

    We define the distance of two strings A and B with same length n is dis A,B =∑ i=0 n−1 |A i −B n−1−i ...

  6. HDU 6103 17多校6 Kirinriki(双指针维护)

    Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑i=0n− ...

  7. Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)

    Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...

  8. 2015多校第6场 HDU 5358 First One 枚举,双指针

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5358 题意:如题. 解法:观察式子发现,由于log函数的存在,使得这个函数的值域<=34,然后我 ...

  9. hdu 2489(枚举 + 最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2489 思路:由于N, M的范围比较少,直接枚举所有的可能情况,然后求MST判断即可. #include ...

随机推荐

  1. UITextfield 允许和禁止编辑

    1.enabled属性 2.resignFirstResponder,设置的时候,如果不起作用,可以延时一会儿,因为键盘升起需要时间. dispatch_after(dispatch_time(DIS ...

  2. 前端自动化-gulp入门

    前不久本人写了一篇关于gulp安装和配置的文章,其实当时还是懵逼的状态,但是今天再次温习了一遍,感觉对整个流程有个整体的理解了,下面以一个实例给大家分享下我的经验供参考和学习. 1.首先安装nodej ...

  3. 二、制作BOM表格--物料表格--Bill of Materials

    二.制作BOM表格--物料表格--Bill of Materials 公司会根据这个表格进行相关元器件的采购--以及后期的贴片上彩 操作: .dsn--Tools--Bill of Materials ...

  4. (转)Java 原子性引用 AtomicReference

    链接:https://www.jianshu.com/p/882d0e2c3ea6 來源:简书  作者:专职跑龙套 AtomicReference An object reference that m ...

  5. 测开之路三十二:Flask基础之错误与重定向

    错误处理,框架默认的错误为:not Found 可以捕获,并自定义 准备一张自定义图片,放在static文件夹下,并在template下创建一个html文件,引用该图片 捕获404状态,返回自定义页面 ...

  6. 【转】Selenium 加载Chrome/Firefox浏览器配置文件

    原文地址:https://www.cnblogs.com/eastonliu/p/9083982.html Selenium启动浏览器时,默认是打开一个新用户,不会加载原有的配置以及插件.但有些时候我 ...

  7. Bootstrap 学习笔记3 输入框和导航组件

    导航组件: 导航条组件: 导航条代码: <nav class="navbar navbar-default"> <div class="containe ...

  8. Html5 学习笔记 【PC固定布局】 实战2 导航栏搜索区域

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...

  9. Vue2.0---webpack打包知识点-1

    打包上线或者将项目做成产品的肯定不希望暴露自己源码 在config的index.js中将productionGzip设置为false即可.(使之不生成.map文件). 对Vue-cli的webpack ...

  10. 洛谷 P1972 [SDOI2009]HH的项链——树状数组

    先上一波题目 https://www.luogu.org/problem/P1972 这道题是询问区间内不同数的个数 明显不是正常的数据结构能够维护的 首先考虑 因为对于若干个询问的区间[l,r],如 ...