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 ...
随机推荐
- 迁移到 Linux:使用 sudo | Linux 中国
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/F8qG7f9YD02Pe/article/details/80976600 https://mmbi ...
- 纯代码实现WordPress上传图片自动重命名的方法
在我们使用 WordPress 发布文章时,经常都需要添加图片.多媒体什么的.然而,大家都知道 WordPress 是舶来物,对于中文用户来说,我们都会把图片命名为中文的,由于 WordPress 机 ...
- 实习培训——Java基础(3)
实习培训——Java基础(3) 1 Java 继承 1.1 super和this关键字 super关键字:我们可以通过super关键字来实现对父类成员的访问,用来引用当前对象的父类. this关键字 ...
- XPath轴
XPath 轴翻译:Linyupark / 2006-03-24 The XML Example DocumentXML举例文档 We will use the following XML docum ...
- Andrew Ng-ML-第十六章-异常检测
1.问题动机 图1.飞机发动机检测例子 对飞机引擎的例子,如果选取了两个特征x1热量产生度,x2震动强度.并得到如下的图,如果有一个新的引擎来检测其是否正常,x_test,那么此时如果点落在和其他点正 ...
- QC质量管理七大手法
1.层别法 层别法就是将大量有关某一特定主题的观点.意见或想法按组分类,将收集到的大量的数据或资料按相互关系进行分组,加以层别.层别法一般和柏拉图.直方图等其它七大手法结合使用,也可单独使用. 2.查 ...
- jenkins maven testng selenium自动化持续集成
准备环境 首先我们新建一个maven的工程,并且在pom.xml中配置好我们依赖的一些jar包 <dependencies> <dependency> <groupId& ...
- 174. Dungeon Game(动态规划)
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 7. Graph Algorithms and Implementation Techniques
uva 10803 计算从任何一个点到图中的另一个点经历的途中必须每隔10千米 都必须有一个点然后就这样 floy 及解决了 ************************************* ...
- C# 将字节流转换为图片的实例方法(转)
代码如下: usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem. ...