hdu 6103 Kirinriki (枚举对称中心+双指针)
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.
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
[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
#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 (枚举对称中心+双指针)的更多相关文章
- HDU 6103 Kirinriki (思维 双指针)
Kirinriki Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- hdu 6103(Kirinriki)
题目链接:Kirinriki 题目描述: 找两个不重叠的字符串A,B. 使得dis(A,B)<=m;\(dis(A,B)= \sum _{i=0}^{n-1} \left | A_i-B_{n- ...
- HDU 6103 Kirinriki(尺取法)
http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选 ...
- 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= ...
- 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 ...
- 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− ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- 2015多校第6场 HDU 5358 First One 枚举,双指针
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5358 题意:如题. 解法:观察式子发现,由于log函数的存在,使得这个函数的值域<=34,然后我 ...
- hdu 2489(枚举 + 最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2489 思路:由于N, M的范围比较少,直接枚举所有的可能情况,然后求MST判断即可. #include ...
随机推荐
- php strip_tags()函数 语法
php strip_tags()函数 语法 作用:剥去字符串中的 HTML 标签 语法:strip_tags(string,allow) 参数: 参数 描述 string 必须,规定要检查的字符串. ...
- ADSL(Asymmetric Digital Subscriber Loop)技术
上行带宽,下行带宽 宽带上行下行是指一般ADSL上网方式上行与下行速率,上行就是从电脑上传的速度,下行就是从网络上的主机下载速度,一般下行速率比较高! ADSL(Asymmetric Digital ...
- POJ 2114 (点分治)
题目:https://vjudge.net/contest/307753#problem/B 题意:求树中路径和=k的点对是否存在 思路:点分治,这个题其实和上一题洛谷一样,只是这个数据强,我们不能直 ...
- 禅道安装--结合openldap
原文地址: https://blog.csdn.net/plei_yue/article/details/79075298 ldap结合禅道(需要神道不是开源版) https://www.cnblog ...
- idea中git回退远程仓库版本
工作中遇到,代码已提交并已提交到远程仓库,现需要回退到之前版本,记录如下: 记录当前版本的版本号和需要回退到版本的版本号. current version:85e7f32dfe421c5892a4e2 ...
- Jmeter 线程之间传递参数
1.获取返回结果中的值,设置为变量 2.在该请求下,添加BeanShell PostProcessor插件,使用__setProperty函数,将之前的变量转换成全局变量 3.在另一个线程组中引用该变 ...
- LeetCode 最短无序连续子数组
题目链接:https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray/ 题目大意: 略. 分析: 如果排序区间为 [L ...
- ubuntu中下载pycharm并添加到桌面
方法一:下载Pycharm与安装 下载地址:https://www.jetbrains.com/pycharm/ Pycharm专业版和社区版对大多数人来说差别不大,区别如下: 我们下载Linux的社 ...
- 美团2018年CodeM大赛-资格赛
https://www.nowcoder.com/acm/contest/138#question A.下单 水题…… B.可乐 题意:求期望 代码: #include<iostream> ...
- JS的部分部分疑问和小结
2015/9/1 1.在字符串中没有可以所需要查找的"X"的时候,返回的值 java:lastIndexof -1 js: IndexOf undefined... 2015/ ...