HDU 6103 Kirinriki(尺取法)
http://acm.hdu.edu.cn/showproblem.php?pid=6103
题意:
给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值
,要求dis值小于等于m,求能选的子串的最大长度。
思路:
由于这两个子串是互不重叠的,那么这两个子串之间的间隔可以是奇数也可以是偶数,针对这两种情况我们枚举中心点,然后尺取法处理,具体看代码就懂了。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,ll> pll;
const int INF = 0x3f3f3f3f;
const int maxn=+; int n, m;
int cnt;
int ans;
char s[maxn];
int tmp[maxn]; void check()
{
int l=,r=;
int dis=;
while(r<cnt)
{
dis+=tmp[++r];
while(dis>m) dis-=tmp[++l];
ans=max(ans,r-l);
}
} int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&m);
scanf("%s",s+);
n=strlen(s+); ans=;
for(int i=;i<=n;i++) //中间相隔奇数
{
int l=i-,r=i+;
cnt=;
while(l> && r<=n) {tmp[++cnt]=abs(s[l]-s[r]);l--;r++;}
check();
} for(int i=;i<=n;i++) //中间相隔偶数
{
int l=i,r=i+;
cnt=;
while(l> && r<=n) {tmp[++cnt]=abs(s[l]-s[r]);l--;r++;}
check();
} printf("%d\n",ans);
}
return ;
}
HDU 6103 Kirinriki(尺取法)的更多相关文章
- 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 5672 String 尺取法
String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem D ...
- HDU 5672 String 尺取法追赶法
String Problem Description There is a string S.S only contain lower case English character.(10≤lengt ...
- HDU 6103 Kirinriki (思维 双指针)
Kirinriki Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- hdu 6103(Kirinriki)
题目链接:Kirinriki 题目描述: 找两个不重叠的字符串A,B. 使得dis(A,B)<=m;\(dis(A,B)= \sum _{i=0}^{n-1} \left | A_i-B_{n- ...
- hdu 6103 Kirinriki (枚举对称中心+双指针)
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑(i=0 ...
- hdu 5510 Bazinga KMP+尺取法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:至多50组数据,每组数据至多500个字符串,每个字符串的长度最长为2000.问最大的下标( ...
- HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))
小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
随机推荐
- memcached-session-manager 教程实现session共享
1简单介绍 1.1决定用什么序列化策略. 1.2配置tomcat 1.2.1加入 memcached-session-manager jar 包到tomcat中. ...
- Python3学习之路~2.1 列表、元组操作
列表 列表是我们以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作. 定义列表(list) names=['Amy','Bob','Cindy','David'] 通过下标访问列 ...
- PAT 1101 Quick Sort[一般上]
1101 Quick Sort(25 分) There is a classical process named partition in the famous quick sort algorith ...
- [LeetCode] 717. 1-bit and 2-bit Characters_Easy
We have two special characters. The first character can be represented by one bit 0. The second char ...
- python的三种字符串格式化方法
1.最方便的 print 'hello %s and %s' % ('df', 'another df') 但是,有时候,我们有很多的参数要进行格式化,这个时候,一个一个一一对应就有点麻烦了,于是就有 ...
- windows8.1的启动目录的路径
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\ 或者使用斜杠表示,就像这样: C:/ProgramData/Microsof ...
- 2:3 Action的配置
< 一 作用> 一:封装工作单元(相当于是控制层,封装出modelAndView) 二:定义name属性接受前台传过来的数据,再定义message属性,用于存放返回前台页面展示的数 据,实 ...
- Baidu 推荐技术平台(offer)
一面: 1 自我介绍 项目介绍. 2 RNN 原理,LSTM原理,GBDT原理,XGB与GBDT的改进. 3 多模匹配,字典树,链表环找入口. 4 c++ static 关键字 5 多线程,线程安全 ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON FastThreshold2
zw版[转发·台湾nvp系列Delphi例程]HALCON FastThreshold2 FastThreshold_Delphi_2.PNG procedure TForm1.Button1Clic ...
- Windows批处理程序bat
@echo off 关闭回显,否则脚本中的命令都会输出,关闭后只显示结果. setlocal ENABLEDELAYEDEXPANSION 在for循环中变量扩展时需要用到 copy /Y ms ...