2017 Multi-University Training Contest
来源:互联网 发布:萧航网络 编辑:程序博客网 时间:2024/06/09 17:44
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
#include <iostream>#include <stdio.h>#include <string.h>#include <queue>#include <cmath>#include <stdlib.h>using namespace std;typedef long long LL;const LL MAX = 5000+10;const LL mod = 7654321; const double eps = 1e-8;const double PI = acos(-1.0);#define zero(x) (((x)>0?(x):(-x))<eps)int ans, m, len;char s[MAX];void solve(int a, int b){ int l = 0, r = 0, sum = 0; while(a+r<b-r){ sum+=abs(s[a+r]-s[b-r]); r++; if(b-l-a-l+1<=ans*2)break; //printf("%d %d\n", l, r); //printf("%d %d %d %d\n", a+l, a+r, b-r, b-l); while(sum>m&&r>l){ sum-=abs(s[a+l]-s[b-l]); l++; } if(ans<r-l)ans = r-l; }}int main() { int t; scanf("%d", &t); while(t--){ scanf("%d", &m); scanf("%s", s); len = strlen(s); ans = 0; for(int i = 1; i<len; ++i){ solve(0, i); } for(int i = 0; i<len-1; ++i){ solve(i,len-1); } printf("%d\n", ans); } return 0;}
阅读全文
0 0
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 前端题部分总结(二)
- editplus 用本地浏览器打开html文件
- 【.net 深呼吸】自己动手来写应用程序设置类
- PHP中的HTTP认证
- IDEA 'Generics are not supported at this language level'报错解决
- 2017 Multi-University Training Contest
- Linux 基本常用命令 用户 useradd,userdel,su,passwd
- World final 2012 (Chips Challenge-无源汇最小费用流)
- 通过API文档查询Math类的方法,打印出近似圆,只要给定不同半径,圆的大小随之发生改变
- 日常问题总结(1)
- 你真的了解UIView吗?
- 在Lua中使用自定义类——tolua++工具使用
- 矩阵乘法优化--poj3318 随机矩阵
- onvif soap接口代码框架的关联