题意:给你一个串,问期中至少出现m次的最长子串及其起始位置的坐标。

思路:hash+LCP+二分答案

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn = + ;
const int x = ;
int n, m, pos;
unsigned long long H[maxn], xp[maxn]; unsigned long long hash[maxn];
int rank[maxn]; int cmp(const int& a, const int& b)
{
return hash[a] < hash[b] || (hash[a] == hash[b] && a < b);
} int possible(int L)
{
int c = ;
pos = -;
for(int i = ; i < n-L+; i++)
{
rank[i] = i;
hash[i] = H[i] - H[i+L]*xp[L];
}
sort(rank, rank+n-L+, cmp);
for(int i = ; i < n-L+; i++)
{
if(i == || hash[rank[i]] != hash[rank[i-]])
c = ;
if(++c >= m)
pos = max(pos, rank[i]);
}
return pos >= ;
} int main()
{
char s[maxn];
while(scanf("%d", &m) == && m)
{
scanf("%s", s);
n = strlen(s);
H[n] = ;
for(int i = n-; i >= ; i--)
H[i] = H[i+]*x + (s[i] - 'a');
xp[] = ;
for(int i = ; i <= n; i++)
xp[i] = xp[i-]*x;
if(!possible())
printf("none\n");
else
{
int L = , R = n+;
while(R - L > )
{
int M = L + (R-L)/;
if(possible(M))
L = M;
else R = M;
}
possible(L);
printf("%d %d\n", L, pos);
}
}
return ;
}

uvalive 4513 Stammering Aliens的更多相关文章

  1. UVALive - 4513 Stammering Aliens ——(hash+二分 || 后缀数组加二分)

    题意:找一个出现了m次的最长子串,以及这时的最右的位置. hash的话代码还是比较好写的,,但是时间比SA多很多.. #include <stdio.h> #include <alg ...

  2. Hash(LCP) || 后缀数组 LA 4513 Stammering Aliens

    题目传送门 题意:训练指南P225 分析:二分寻找长度,用hash值来比较长度为L的字串是否相等. #include <bits/stdc++.h> using namespace std ...

  3. UVA 12206 - Stammering Aliens(后缀数组)

    UVA 12206 - Stammering Aliens 题目链接 题意:给定一个序列,求出出现次数大于m,长度最长的子串的最大下标 思路:后缀数组.搞出height数组后,利用二分去查找就可以 这 ...

  4. Stammering Aliens

    Stammering Aliens Time Limit: 2000MS   Memory Limit: 65536K       Description Dr. Ellie Arroway has ...

  5. Uva12206 Stammering Aliens 后缀数组&&Hash

    Dr. Ellie Arroway has established contact with an extraterrestrial civilization. However, all effort ...

  6. HDU4080 Stammering Aliens(二分 + 后缀数组)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4080 Description Dr. Ellie Arroway has establish ...

  7. UVa 12206 (字符串哈希) Stammering Aliens

    体验了一把字符串Hash的做法,感觉Hash这种人品算法好神奇. 也许这道题的正解是后缀数组,但Hash做法的优势就是编码复杂度大大降低. #include <cstdio> #inclu ...

  8. 【HDOJ】4080 Stammering Aliens

    1. 题目描述给定一个长为$n \in [1, 4000]$的字符串,求其中长度最长的子串,并且该子串在原串中出现至少$m$次,并求最右起始位置. 2. 基本思路两种方法:二分+后缀数组,或者二分+哈 ...

  9. uva 12206 - Stammering Aliens

    基于hash的LCP算法: #include<cstdio> #include<cstring> #include<algorithm> #define maxn ...

随机推荐

  1. winform访问url传参有返回值

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;usi ...

  2. CSS样式表引用方式

    最近讲课中,有些学员对调用样式表老是有含糊不清?大体说来有四种方式: 1.外部文件引用方式;(推荐使用) 2.使用@import引用外部CSS文件; 3.内部文档头方式也叫内嵌法调用; 4.直接插入式 ...

  3. linux为命令取别名

    在linux的命令中,有些命令很长并且经常使用到,我们可以为命令添加一个别名,格式如下: $ alias 别名='命令' 例如: # 列出home文件夹的文件 $ alias lsh='ls -l / ...

  4. SaaS系列介绍之四:我国SaaS市场发展

    1 引言 那些没有经验的问题解决者们,几乎无一例外,都是去匆忙地寻找解决办法,而不是先给要解决的问题下定义.                                               ...

  5. SQLite设置主键自动增长及插入语法

    SQLite中,一个自增长字段定义为INTEGER PRIMARY KEY AUTOINCREMENT,那么在插入一个新数据时,只需要将这个字段的值指定为NULL,即可由引擎自动设定其值,引擎会设定为 ...

  6. Git教程之撤销修改(7)

    自然,你是不会犯错的.不过现在是凌晨两点,你正在赶一份工作报告,你在readme.txt中添加了一行:

  7. 221. Maximal Square

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...

  8. 如何引用传递String Boolean 等,并改变他们的值

    如何引用传递String Boolean 等,并改变他们的值 采用list, 在存入位置改变list的值 如 list.add(true); list.remove(0); list.add(fals ...

  9. XST综合、实现过程包含哪些步骤

    2013-06-25 18:53:50 在ISE的主界面的处理子窗口的synthesis的工具可以完成下面的任务: 查看RTL原理图(View RTL schematic) 查看技术原理图(View ...

  10. bzoj1015:1015: [JSOI2008]星球大战starwar

    应该是全部读入之后再添加边用并查集就可以了. yyl用空间换时间.u[]v[]等将边预存起来. #include<cstdio> #include<cstring> #incl ...