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,让你找一条从根结点走到第 ...
随机推荐
- java8 write file 写文件
1.用BufferedWriter写入文件 //Get the file reference Path path = Paths.get("c:/output.txt"); //U ...
- zookeeper图形工具——zkui
虽然zookeeper安装包提供了客户端工具zkcli,但是命令特别少 ,每次想看看里面的节点信息特别费劲. 幸好有图形工具——zkui,https://github.com/echoma/zkui, ...
- 51nod 小Z的trie(Trie+广义SAM)
[题目链接] http://www.51nod.com/contest/problem.html#!problemId=1647 [题意] 给定一个n个字符串的Trie,每次询问一个字符串在Trie上 ...
- 【leetcode 简单】 第八十七题 两整数之和
不使用运算符 + 和-,计算两整数a .b之和. 示例: 若 a = 1 ,b = 2,返回 3. class Solution: def getSum(self, a, b): "&quo ...
- Python基础入门(一)
1.在线教程 2.Python下载地址,安装步骤,就是next.next... 3.配置环境变量(win8) 电脑 --> 属性 --> 高级系统设置 --> 环境变量,找到系统变量 ...
- 2017 jq 总结
$(el).parent() 获取父级元素 .parents('th') 获取祖元素th .parentsUntil("th") 找到 ...
- opencv 摄像头
VideoCapture cap(); if(!cap.isOpened()) ; Mat frame, edges; namedWindow(); for(;;) { cap >> fr ...
- MS Office CVE-2015-1641 恶意 Exploit 样本分析
MS Office CVE-2015-1641 恶意 Exploit 样本分析 在对最近的一个恶意 MS Office 文档样本进行分析时,我们发现了一些有趣的特性.这个文档利用 CVE-2015-1 ...
- golang的json序列化
json就是简单的数据交换格式,语法类似javascript的对象和列表,是最常见的后端和运行在网页上的js之间的通信格式. encoding: 编码json数据需要使用到Marshal()函数. f ...
- python学习笔记之split()方法与with
Python split()方法 以下内容摘自:http://www.runoob.com/python/att-string-split.html 描述 Python split()通过指定分隔符对 ...