HDU6103-Kirinriki
来源:互联网 发布:mac系统无guid分区重装 编辑:程序博客网 时间:2024/04/25 19:54
Kirinriki
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1691 Accepted Submission(s): 689
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
解题思路:尺取法,用初始串做出一个反转串,然后先对初始串进行枚举,每次枚举先让两个指针指向反转串的第一个字符,先移动尾指针直至和大于m,然后移动一次头指针,再去移动尾指针直至和又大于m,不断循环做这个操作。最后再对反转串进行枚举,操作和初始串一样
#include <iostream>#include <cstdio>#include <cstring>#include <map>#include <set>#include <string>#include <cmath>#include <algorithm>#include <vector>#include <bitset>#include <stack>#include <queue>#include <unordered_map>#include <functional>using namespace std;char s1[5009],s2[5009];int m;int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%s",&m,s1+1); int n = strlen(s1 + 1); for(int i=1; i<=n; i++) s2[i]=s1[n-i+1]; s2[n+1]='\0'; int ma=0; for(int i=1; i<=n; i++) { int l=1,r=1,k=0; while(1) { while(k+abs(s1[i+r-1]-s2[r])<=m&&r+r+i-1<=n) { k+=abs(s1[i+r-1]-s2[r]); r++; } ma=max(ma,r-l); if(r+r+i-1>n) break; k-=abs(s1[i+l-1]-s2[l]); l++; } } for(int i=1; i<=n; i++) { int l=1,r=1,k=0; while(1) { while(k+abs(s2[i+r-1]-s1[r])<=m&&r+r+i-1<=n) { k+=abs(s2[i+r-1]-s1[r]); r++; } ma=max(ma,r-l); if(r+r+i-1>n) break; k-=abs(s2[i+l-1]-s1[l]); l++; } } printf("%d\n",ma); } return 0;}
阅读全文
0 0
- HDU6103-Kirinriki
- HDU6103-Kirinriki
- HDU6103(Kirinriki)
- HDU6103 Kirinriki-dp+二分
- hdu6103 Kirinriki(尺取法)
- Hdu6103 Kirinriki(2017多校第6场)
- hdu6103 Kirinriki 2017多校1008 尺取法
- HDU6103 Kirinriki(区间dp+二分)
- 2017多校训练6-1008:Kirinriki(HDU6103)
- hdu6103-Kirinriki (2017杭电多校联赛第6场)
- HDU6103---Kirinriki(2017多校联赛:滑动窗)
- 噩梦多校6。。HDU6103 Kirinriki(字符串,尺取法)
- hdu6103-2017多校6&尺取法|思维-Kirinriki
- HDU6103
- HDU6103
- hdu6103
- HDU6103
- hdu6103
- [Git]Git的撤消操作-重置,签出和撤消
- html学习
- HTML中Attribute和JavaScript中property区别
- 使用mysql自带工具mysqldump进行全库备份以及source命令恢复数据库
- VIewPager+XListView+RadioButton实现布局
- HDU6103-Kirinriki
- 如何简单方便的用字体代替页面中常见常用的小图标小按钮(上)
- Android的线程
- 【随笔】Android Hybrid App 体系结构
- HDC, CDC, CClientDC, CWindowDC
- Linux C学习--getline()函数
- Hbase单机版测试
- Iterator迭代器
- ThingInJava-IO笔记(IO)