HDU6103(枚举)
来源:互联网 发布:阿里云cdn配置技巧 编辑:程序博客网 时间:2024/06/05 19:22
Kirinriki
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 833 Accepted Submission(s): 327
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
思路:
枚举每个位置作为分割两个字串的中点,特别注意有奇数与偶数的区别。
#include<cstdio>#include<iostream>#include<string.h>#include<math.h> #include<algorithm>using namespace std;int m;char str[5010];int sum[5010];int solve(int l){int ans=0;int s=0;int i=0,j=0;while(1){while(i<l&&s+sum[i]<=m){s+=sum[i];ans=max(ans,i-j+1);i++;}s-=sum[j];j++;if(j>=l) break;}return ans;}void work(int l){int ans=0;for(int i=0;i<l;i++){int c=0;//当以奇数方式分割 for(int j=1;j+i<l&&i-j>=0;j++){sum[c]=abs(str[j+i]-str[i-j]);c++;}ans=max(ans,solve(c));}for(int i=0;i<l;i++){int c=0;//当以偶数方式分割 for(int j=1;j+i-1<l&&i-j>=0;j++){sum[c]=abs(str[j+i-1]-str[i-j]);c++; }ans=max(ans,solve(c));}printf("%d\n",ans);} int main(){int t;scanf("%d",&t);while(t--){int len;scanf("%d",&m);scanf("%s",str);len=strlen(str);work(len);}}
Kirinriki
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 833 Accepted Submission(s): 327
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
阅读全文
0 0
- HDU6103(枚举)
- HDU6103
- HDU6103
- hdu6103
- HDU6103
- hdu6103
- hdu6103-暴力
- HDU6103-Kirinriki
- HDU6103-Kirinriki
- HDU6103(Kirinriki)
- hdu6103(尺取)
- HDU6103 Kirinriki-dp+二分
- hdu6103(尺取)
- hdu6103(尺取法)
- hdu6103 Krinriki(尺取法)
- 2017第六次多校联合hdu6103
- hdu6103 Kirinriki(尺取法)
- Hdu6103 Kirinriki(2017多校第6场)
- java通过UUID生成16位唯一订单号
- Hibernate中如何管理session和批量操作数据
- AngularJS(六)非侵入式javascript
- 常用正则表达式
- Dubbo是什么?
- HDU6103(枚举)
- html5新增元素
- 全屏宽度的图片设置、@2x或@3x高倍图片设置原理
- JS——实现吹气球
- Centos7安装Qt5.5
- Android学习路线
- IIC协议
- struct/class等内存字节对齐问题详解
- 北京房价研究(2017)