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 ...
随机推荐
- ul li剧中对齐
html: <div class="footernav"> <ul> <li>首页</li> <li>文章</li ...
- 008-spring cloud gateway-路由谓词RoutePredicate、RoutePredicateFactory
一.概述 Spring Cloud Gateway将路由作为Spring WebFlux HandlerMapping基础结构的一部分进行匹配. Spring Cloud Gateway包含许多内置的 ...
- mathType插入公式编号,及对公式编号的字体进行修改。调整公式上下间距。
一:插入 公式编号. 1:首先设置公式格式.点击 mathtype>insert number >format 2:有简单格式和 高级格式: https://we ...
- PAT The Best Rank[未作]
1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...
- [LeetCode] 851. Loud and Rich_ Medium tag: DFS
In a group of N people (labelled 0, 1, 2, ..., N-1), each person has different amounts of money, and ...
- Hadoop集群安装-CDH5(5台服务器集群)
CDH5包下载:http://archive.cloudera.com/cdh5/ 架构设计: 主机规划: IP Host 部署模块 进程 192.168.254.151 Hadoop-NN-01 N ...
- java中Integer 和String 之间的转换
java中Integer 和String 之间的转换 将数组转换成字符串:char[] array = {'a','b','c','d','e'};String str = new String(ar ...
- php传值,传地址,传引用的区别
传值, 是把实参的值赋值给行参 那么对行参的修改,不会影响实参的值 传地址 是传值的一种特殊方式,只是他传递的是地址,不是普通的如int 那么传地址以后,实参和行参都指向同一个对象 传 ...
- redis error It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
应用redis出现如下错误 It was not possible to connect to the redis server(s); to create a disconnected multip ...
- linux常用命令:vmstat 命令
vmstat 是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体 情况进行统计,不足之处是无法对某个进程进 ...