hdu3518 Boring counting
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=3518
题目:
Boring counting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3187 Accepted Submission(s): 1320
Take aaaa as an example.”a” apears four times,”aa” apears two times without overlaping.however,aaa can’t apear more than one time without overlaping.since we can get “aaa” from [0-2](The position of string begins with 0) and [1-3]. But the interval [0-2] and [1-3] overlaps each other.So “aaa” can not take into account.Therefore,the answer is 2(“a”,and “aa”).
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm> const int N = ;
int sa[N],s[N],wa[N], wb[N], ws[N], wv[N];
int rank[N], height[N]; bool cmp(int r[], int a, int b, int l)
{
return r[a] == r[b] && r[a+l] == r[b+l];
}
void calheight(int r[], int sa[], int n)
{
int i, j, k = ;
for (i = ; i <= n; ++i) rank[sa[i]] = i;
for (i = ; i < n; height[rank[i++]] = k)
for (k?k--:, j = sa[rank[i]-]; r[i+k] == r[j+k]; k++);
}
void da(int r[], int sa[], int n, int m)
{
int i, j, p, *x = wa, *y = wb;
for (i = ; i < m; ++i) ws[i] = ;
for (i = ; i < n; ++i) ws[x[i]=r[i]]++;
for (i = ; i < m; ++i) ws[i] += ws[i-];
for (i = n-; i >= ; --i) sa[--ws[x[i]]] = i;
for (j = , p = ; p < n; j *= , m = p)
{
for (p = , i = n - j; i < n; ++i) y[p++] = i;
for (i = ; i < n; ++i) if (sa[i] >= j) y[p++] = sa[i] - j;
for (i = ; i < n; ++i) wv[i] = x[y[i]];
for (i = ; i < m; ++i) ws[i] = ;
for (i = ; i < n; ++i) ws[wv[i]]++;
for (i = ; i < m; ++i) ws[i] += ws[i-];
for (i = n-; i >= ; --i) sa[--ws[wv[i]]] = y[i];
for (std::swap(x, y), p = , x[sa[]] = , i = ; i < n; ++i)
x[sa[i]] = cmp(y, sa[i-], sa[i], j) ? p- : p++;
}
calheight(r,sa,n-);
} int check(int lc,int x)
{
int mi=sa[],mx=sa[],ans=;
for(int i=;i<=lc;i++)
{
if(height[i]<x)
{
if(mx-mi>=x)
ans++;
mx=mi=sa[i];
}
else
{
mx=std::max(mx,sa[i]);
mi=std::min(mi,sa[i]);
}
}
if(mx-mi>=x)ans++;
return ans;
}
char ss[N];
int main()
{
while(scanf("%s",ss)==)
{
if(ss[]=='#')break;
int la=strlen(ss),n=,ans=;
for(int i=;i<la;i++)
s[n++]=ss[i]-'a'+;
s[n]=;
da(s,sa,n+,);
for(int i=;i<=n/;i++)
ans+=check(n,i);
printf("%d\n",ans);
}
return ;
}
hdu3518 Boring counting的更多相关文章
- hdu3518 Boring counting(后缀数组)
Boring counting 题目传送门 解题思路 后缀数组.枚举每种长度,对于每个字符串,记录其最大起始位置和最小起始位置,比较是否重合. 代码如下 #include <bits/stdc+ ...
- hdu3518 Boring Counting[后缀排序]
裸的统计不同的重复出现子串(不重叠)种数的题.多次使用后缀排序要注意小细节.y数组在重复使用时一定要清空,看那个line25 +k就明白了 ,cnt也要清空,为什么就不说了 #include<b ...
- [HDU3518]Boring counting(后缀数组)
传送门 求出现超过1次的不重叠子串的个数 根据论文中的方法. 枚举子串的长度 k. 用 k 给 height 数组分组,每一组求解,看看当前组的位置最靠后的后缀和位置最靠前的后缀所差个数是否大于长度, ...
- sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)
Boring Counting Time Limit: 3000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In this problem you a ...
- HDU 4358 Boring counting(莫队+DFS序+离散化)
Boring counting Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Others) ...
- sdutoj 2610 Boring Counting
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2610 Boring Counting Time ...
- hdu 4358 Boring counting dfs序+莫队+离散化
Boring counting Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Others) ...
- 后缀数组 --- HDU 3518 Boring counting
Boring counting Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3518 Mean: 给你一个字符串,求:至少出 ...
- SDUT 2610 Boring Counting(离散化+主席树区间内的区间求和)
Boring Counting Time Limit: 3000MS Memory Limit: 65536KB Submit Statistic Discuss Problem Descriptio ...
随机推荐
- 运动目标检测ViBe算法
一.运动目标检测简介 视频中的运动目标检测这一块现在的方法实在是太多了.运动目标检测的算法依照目标与摄像机之间的关系可以分为静态背景下运动检测和动态背景下运动检测.先简单从视频中的背景类型来讨论. ...
- Hadoop1.2.1 日志格式说明及启停方式
日志格式: 日志名称解析: Hadoop启停的三种方式: . 停止后面的以此类推...... 另外 hadoop-daemons.sh 表示启动多个,比如datanode跟tasktracker在真实 ...
- solr初认识
Solr : Search On Lucene Replication Solr 基本概况 Apache Solr (读音: SOLer) 是一个开源的搜索服务器.Solr 使用 Java 语言开发, ...
- 用Broadcast Receiver刷新数据
①注册广播事件: 注册方式有两种, 一种是静态注册,就是在AndroidManifest.xml文件中定义,注册的广播接收器必须要继承BroadcastReceiver: 另一种是动态注册,是在程序中 ...
- asfd
$$\sum_{i=1}^n a_i=0$$$$f(x)=x^{x^x}$$
- 160414、java上传文件以流方式判断类型
public enum FileType { /** * JEPG. */ JPEG("FFD8FF"), / ...
- SaltStack远程执行-返回MySQL
上一篇:SaltStack远程执行-模块 参考官方文档:https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.my ...
- web安全之xss攻击
xss攻击的全称是Cross-Site Scripting (XSS)攻击,是一种注入式攻击.基本的做法是把恶意代码注入到目标网站.由于浏览器在打开目标网站的时候并不知道哪些脚本是恶意的,所以浏览器会 ...
- C#中命名空间别名的使用
C#中使用命名空间来分割不同的层级,在不同的层级中可以使用相同的类声明和变量声明.在程序中使用不同命名空间的下的相同名称的类时:可以用一下这几种方法进行限定: 1.使用完全限定名 using Syst ...
- Windows10安装MySQL5.6.24
1.解压安装包到指定目录如:E:\Java\mysql-5.6-24-win32 2.在E:\Java\mysql-5.6-24-win32目录下新建my.ini文件,内容如下 [mysqld] ba ...