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 ...
随机推荐
- UIImage添加滤镜
UIImage *image =[UIImage imageNamed:"]; NSArray *arr = [NSArray arrayWithObjects:@"CISRGBT ...
- ASP.NET一个页面的生命周期
在学习ASP.NET页面生命周期前,需要先了解之前的ASP.NET的基本运行机制,在理解ASP.NET基本运行机制原理后,下面将介绍ASP.NET的生命周期中,页面从创建到处理结束的过程中ASP.NE ...
- visio 的使用方法
1:往visio中添加商务图形和形状的方法.例如饼状图. 文件>形状>商务>图表和图形>绘制图表形状 2:visio 画半弧形,用铅笔 3: visio 画的图形,如果想要和v ...
- Python安装sqlite3
今天使用PYthon时,发现错误 ImportError: No module named sqlite 这是因为缺少 SQLITE3的缘故. 下面分享一下解决此问题的方法步骤: 1. 查看是Pyth ...
- PAT Radix[二分][进制转换][难]
1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...
- soft nofile
原创文章,转载请注明出处:http://jameswxx.iteye.com/blog/2096461 写这个文章是为了以正视听,网上的文章人云亦云到简直令人发指.到底最大文件数被什么限制了?too ...
- 测试常用的Oracle11G 命令行指令。
测试常用的Oracle11G 命令行指令. ×××××××××××××××× 登录:
- memset函数使用方法
将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值, 块的大小由第三个参数指定,这个函数通常为新申请的内存做初始化工作, 其返回值为指向S的指针. 需要的头文件 在C中 < ...
- Apache-Shiro介绍
Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码学和会话管理.使用Shiro的易于理解的API,您可以快速.轻松地获得任何应用程序,从最小的移动应用程序到最大的网络 ...
- chrome谷歌浏览器用这种方式清除缓存比较方便了,必须是调试模式才行
chrome谷歌浏览器用这种方式清除缓存比较方便了 PS:必须是调试模式才行,可以不是手机模式 ,有些低版本浏览器可能没有这个功能. ----------------------------- ...