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 ... 
随机推荐
- Java IO流总结(二)-示例
			1.使用文件操作的9大方法完成文件的判断 判断文件或目录是否存在 : exits() 返回值boolean型 * 判断是否是文件: isFile() boolean * 判断是否是目录: isDiec ... 
- php基于SQLite实现的分页功能示例
			php基于SQLite实现的分页功能. 这里操作数据库文件使用的是前面文章<PHP基于PDO实现的SQLite操作类>中的SQLite数据库操作类. 代码: <?php class ... 
- bzoj 4161 Shlw loves matrixI——常系数线性齐次递推
			题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4161 还是不能理解矩阵…… 关于不用矩阵理解的方法:https://blog.csdn.ne ... 
- textarea 根据光标位置添加内容
			// 获取焦点 let txt = document.getElementById("countRule"); let temp = txt.value; txt.focus(); ... 
- LR之分析
			1.Errors(错误统计) 每秒错误数:数值越小越好,通过这个图可以知道,当负载增加的时候,定位何时系统在负载下开始不稳定甚至出错. 2.Transaction(事务) average transa ... 
- js俩习题
			需求,现在要求两个按钮,点击1,背景为红色,点击2,背景为黄色 *****html代码——————————————————————————————————————————————————<!DO ... 
- FVWM使用指南
			www.ctex.org/documents/shredder/fvwm_frame.html 
- python post 发送字符串
			python post 发送一段字符串 把字符串写在表单里,表单用字典格式,字符串作value import requests data={key:str} r=requests.post(url,d ... 
- mysql 用户及权限管理 允许远程连接
			mysq,功能强大的关系型数据库,它的用户管理在开发过程中当然也尤其重要,接下来就看看mysql的用户管理 1.登录数据库 mysql -uroot -p 回车 输入密码... 回车 2.登录成功后, ... 
- TP框架实现文件的下载(主要解决文件存在中文文件名的问题)
			namespace Home\Controller; use Think\Controller; use Org\Net\Http; class IndexController extends Con ... 
