HDU 6103 Kirinriki (思维 双指针)
Kirinriki
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2169 Accepted Submission(s): 879
disA,B=∑i=0n−1|Ai−Bn−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
5
abcdefedcb
[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
【题意】给你一个字符串,找到两个不相交的相同长度的子串,使得|Ai−Bn−1−i|求和小于等于m,求子串最大长度。
【分析】可以枚举前缀,然后双指针,这种做法需要翻转一下再来一次,不懂得可以看看这个样例abcdefghi 答案是 def ghi,然后还可以枚举对称轴,这个不需要翻转。
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 5e3+;;
const int M = ;
const int mod = ;
const int mo=;
const double pi= acos(-1.0);
typedef pair<int,int>pii;
typedef pair<ll,int>P;
int n,m,ans;
char str[N];
void solve(){
for(int len=;len<=n;len++){
for(int l=,r=,res=;r<=len/;r++){
res+=abs(str[r]-str[len-r+]);
while(res>m){
res-=abs(str[l]-str[len-l+]);
l++;
}
ans=max(ans,r-l+);
}
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&m);
scanf("%s",str+);
n=strlen(str+);
ans=;
solve();
reverse(str+,str++n);
solve();
printf("%d\n",ans);
}
return ;
}
HDU 6103 Kirinriki (思维 双指针)的更多相关文章
- hdu 6103 Kirinriki (枚举对称中心+双指针)
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑(i=0 ...
- HDU 6103 Kirinriki(尺取法)
http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选 ...
- hdu 6103(Kirinriki)
题目链接:Kirinriki 题目描述: 找两个不重叠的字符串A,B. 使得dis(A,B)<=m;\(dis(A,B)= \sum _{i=0}^{n-1} \left | A_i-B_{n- ...
- 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 5776 sum (思维题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续 ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- Binary Tree HDU - 5573 (思维)
题目链接: B - Binary Tree HDU - 5573 题目大意: 给定一颗二叉树,根结点权值为1,左孩子权值是父节点的两倍,右孩子是两倍+1: 给定 n 和 k,让你找一条从根结点走到第 ...
随机推荐
- 牛市必备的三个条件,A股现在还差几个
1.国家政策 2.中美贸易 3.资金支持 A股变化如神! 自本月10日受美股大跌的影响后,A股先是随之震荡跳水,千股跌停:随后因高层力挺和政策支持而V型反转,集体涨停:接着上演过山车走势,有时涨得令人 ...
- 外卖(food) & 洛谷4040宅男计划 三分套二分&贪心
food评测传送门 [题目描述] 叫外卖是一个技术活,宅男宅女们一直面对着一个很大的矛盾,如何以有限的金钱在宿舍宅得尽量久. 外卖店一共有 N 种食物,每种食物有固定的价钱 Pi 与保质期 Si ...
- python最大最小距离算法贴近度评价法
1.大最小贴近度评价法 概念: 贴近度表示两个模糊几何之间的彼此接近程度,在模糊模式识别方法中采用贴近度的大小识别待判别模糊子集的模式类别.为衡量待识别子集的类别,需要判别各个阶段与标杆模糊集合之间的 ...
- C# Json字符串反序列化
using DevComponents.DotNetBar; using MyControl; using Newtonsoft.Json; using System; using System.Co ...
- linux挂载光盘
1.找到光盘的位置 ls -l /dev |grep cdrom mount /dev/sr0 /mnt [root@node2 /]# ls -l /dev |grep cdrom lrwxrwx ...
- MySQL分布式集群之MyCAT(一)简介【转】
隔了好久,才想起来更新博客,最近倒腾的数据库从Oracle换成了MySQL,研究了一段时间,感觉社区版的MySQL在各个方面都逊色于Oracle,Oracle真的好方便!好了,不废话,这次准备记录一些 ...
- [转]在C#程序设计中使用Win32类库
http://blog.163.com/j_yd168/blog/static/496797282008611326218/ C# 用户经常提出两个问题:“我为什么要另外编写代码来使用内置于 ...
- Pytorch数据读取框架
训练一个模型需要有一个数据库,一个网络,一个优化函数.数据读取是训练的第一步,以下是pytorch数据输入框架. 1)实例化一个数据库 假设我们已经定义了一个FaceLandmarksDataset数 ...
- 使用postman做接口测试(三)
三,接口用例的设计 个人感觉用例的设计才是重要的哈,网上查了一些资料总结了一下 1.业务流程测试 通过性验证: 1, 按照接口文档上的参数,正常传参,是否可以返回正确的结果 2, 是否满足前提条件,比 ...
- java基础32 List集合下的ArrayList集合
单例集合体系: ---------| collection 单例集合的根接口--------------| List 如果实现了list接口的集合类,具备的特点:有序,可重复 注:集合 ...