2017杭电多校第六场1008 Kirinriki
来源:互联网 发布:js如何让下拉菜单 编辑:程序博客网 时间:2024/06/06 08:29
传送门
Total Submission(s): 1012 Accepted Submission(s): 400
Statistic | Submit | Discuss | Note
题意: 已知字符串S,要求不重叠的最长子串长度,并满足两子串距离最大不超过m
Kirinriki
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1012 Accepted Submission(s): 400
Problem Description
We define the distance of two strings A and B with same length n is
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.
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
Each case begins with one line with one integers m : the limit distance of substring.
Then a string S follow.
Limits
Each character in the string is lowercase letter,
Output
For each test case output one interge denotes the answer : the maximum length of the substring.
Sample Input
15abcdefedcb
Sample Output
5Hint[0, 4] abcde[5, 9] fedcbThe distance between them is abs('a' - 'b') + abs('b' - 'c') + abs('c' - 'd') + abs('d' - 'e') + abs('e' - 'f') = 5
Source
2017 Multi-University Training Contest - Team 6
Recommend
liuyiding | We have carefully selected several similar problems for you: 6107 6106 6105 6104 6103
/*思路:由于字符串很短,所以可以枚举前缀和后缀在枚举的子串内采用尺取法将区间等分,利用sum不大于m的条件双指针同时遍历两个区间,更新最大值即可*/#include<bits/stdc++.h>#include<iostream>#include<stdio.h>using namespace std;const int maxn=5e3+10;int m,nl,ans;//nl表示字符串长度,ans代表最后返回的子串长度char s[maxn];void solve(){ for(int i=2;i<=nl;i++)//i表示从总串中取出的子串长度 { int o=i/2; int l=0,n=0,sum=0; for(int j=0;j<o;j++) { sum+=abs(s[j]-s[i-j-1]); if(sum<=m)n++,ans=max(ans,n); else { sum-=abs(s[l]-s[i-l-1]); sum-=abs(s[j]-s[i-j-1]); l++; j--; n--; } } }}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d %s",&m,s); nl=strlen(s); ans=0; solve(); reverse(s,s+nl); solve(); printf("%d\n",ans); } return 0;}
阅读全文
1 0
- 2017杭电多校第六场1008 Kirinriki
- 2017杭电多校第六场 1008 Kirinriki(暴力)HDU 6103
- hdu6103-Kirinriki (2017杭电多校联赛第6场)
- Hdu6103 Kirinriki(2017多校第6场)
- HDU 6103 Kirinriki (字符串翻转 尺取法 17多校第六场)
- HDU 6013 Kirinriki (字符串反转+尺取法 17多校赛第六场)
- 2017杭电多校第六场03Inversion
- 2017杭电多校第六场1011Classes
- hdu6103 Kirinriki 2017多校1008 尺取法
- HDU6103 Kirinriki(尺取法,2017 HDU多校联赛 第6场)
- 2017杭电多校第六场 1003 Inversion(暴力)HDU 6098
- 2017杭电多校第六场 1011 (勉强算容斥吧)HDU 6106
- 2017杭电多校第六场 1010 Gameia(博弈)HDU6105
- 2017多校联合第六场1008/hdu 6103
- 2017多校训练6-1008:Kirinriki(HDU6103)
- HDU-2017 多校训练赛6-1008-Kirinriki
- 2017多校六 1008题 hdu 6103 Kirinriki 尺取法
- 多校第六场1008---MU Puzzle
- struts2重点、精华、用法总结(三):Action相关专题
- 创建博客!
- linux powermanager 之 wakeup
- 研发喜欢和怎样的产品经理干
- 文章标题
- 2017杭电多校第六场1008 Kirinriki
- nginx 惊群现象
- jdk和jre有什么区别
- easyui datagrid 隐藏
- [PlantSimulation]Transporter运输工具的详细用法(四)
- HDU 6102 GCDispower(莫比乌斯反演)
- 子线程的正确的开启方式
- 栈应用之括号匹配
- java运行时异常与一般异常有何异同?