SPOJ220---Relevant Phrases of Annihilation(后缀数组+二分,对后缀分组)

手把手教你学Simulink——基于Simulink的无感FOC(滑模观测器+PLL)实战 本文详细介绍了基于Simulink的无感FOC(滑模观测器+PLL)实现方法。主要内容包括:1)SMO+PLL原理精讲,阐述滑模观测器核心思想和PLL的作用;2)系统架构全景图展示;3)Simulink建模全流程,从基础FOC框架到SMO和PLL模块的实现;4)关键参数整定指南和工程实践要点;5)仿真结果分析及常见问题解决方案。该方法可有效替代机械传感器,降低成本并提高可靠性,适用于空调压缩机、电动汽车水泵等工业场景。文章还提供了详细的调试建议和动手实践指导。 阅读详情

You are the King of Byteland. Your agents have just intercepted a batch of encrypted enemy messages concerning the date of the planned attack on your island. You immedietaly send for the Bytelandian Cryptographer, but he is currently busy eating popcorn and claims that he may only decrypt the most important part of the text (since the rest would be a waste of his time). You decide to select the fragment of the text which the enemy has strongly emphasised, evidently regarding it as the most important. So, you are looking for a fragment of text which appears in all the messages disjointly at least twice. Since you are not overfond of the cryptographer, try to make this fragment as long as possible.
Input

The first line of input contains a single positive integer t<=10, the number of test cases. t test cases follow. Each test case begins with integer n (n<=10), the number of messages. The next n lines contain the messages, consisting only of between 2 and 10000 characters ‘a’-‘z’, possibly with some additional trailing white space which should be ignored.
Output

For each test case output the length of longest string which appears disjointly at least twice in all of the messages.
Example

Input:
1
4
abbabba
dabddkababa
bacaba
baba

Output:
2

(in the example above, the longest substring which fulfills the requirements is ‘ba’)

简单的后缀数组应用,首先还是老套路,把串都连在一起,中间用没出现过的并且不同的字符隔开,求出后缀数组,然后二分答案,对后缀分组,用3个数组,第一个记录每一组的后缀中,每个字符串中出现的后缀的个数,剩下两个分别存每个字符串里最靠前的和最靠后的后缀的起始位置

/*************************************************************************
    > File Name: SPOJ-220.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年04月07日 星期二 21时21分41秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

int pos[122000];
class SuffixArray
{
    public:
        static const int N = 122000;
        int init[N];
        int X[N];
        int Y[N];
        int Rank[N];
        int sa[N];
        int height[N];
        int buc[N];
        int cnt[100];
        int MAXS[100];
        int MINS[100];
        int LOG[N];
        int dp[N][20];
        int size;

        void clear()
        {
            size = 0;
        }

        void insert(int n)
        {
            init[size++] = n;
        }

        bool cmp(int *r, int a, int b, int l)
        {
            return (r[a] == r[b] && r[a + l] == r[b + l]);
        }

        void getsa(int m = 256) //m一般为最大值+1
        {
            init[size] = 0;
            int l, p, *x = X, *y = Y, n = size + 1;
            for (int i = 0; i < m; ++i)
            {
                buc[i] = 0;
            }
            for (int i = 0; i < n; ++i)
            {
                ++buc[x[i] = init[i]];
            }
            for (int i = 1; i < m; ++i)
            {
                buc[i] += buc[i - 1];
            }
            for (int i = n - 1; i >= 0; --i)
            {
                sa[--buc[x[i]]] = i;
            }
            for (l = 1, p = 1; l <= n && p < n; m = p, l *= 2)
            {
                p = 0;
                for (int i = n - l; i < n; ++i)
                {
                    y[p++] = i;
                }
                for (int i = 0; i < n; ++i)
                {
                    if (sa[i] >= l)
                    {
                        y[p++] = sa[i] - l;
                    }
                }
                for (int i = 0; i < m; ++i)
                {
                    buc[i] = 0;
                }
                for (int i = 0; i < n; ++i)
                {
                    ++buc[x[y[i]]];
                }
                for (int i = 1; i < m; ++i)
                {
                    buc[i] += buc[i - 1];
                }
                for (int i = n - 1; i >= 0; --i)
                {
                    sa[--buc[x[y[i]]]] = y[i];
                }
                int i;

                for (swap(x, y), x[sa[0]] = 0, p = 1, i = 1; i < n; ++i)
                { 
                    x[sa[i]] = cmp(y, sa[i - 1], sa[i], l) ? p - 1 : p++; 
                }
            }
        }

        void getheight()
        {
            int h = 0, n = size;
            for (int i = 0; i <= n; ++i)
            {
                Rank[sa[i]] = i;
            }
            height[0] = 0;
            for (int i = 0; i < n; ++i)
            {
                if (h > 0)
                {
                    --h;
                }
                int j =sa[Rank[i] - 1];
                for (; i + h < n && j + h < n && init[i + h] == init[j + h]; ++h);
                height[Rank[i] - 1] = h;
            }
        }   

        //预处理每一个数字的对数,用于rmq,常数优化
        void initLOG()
        {
            LOG[0] = -1;
            for (int i = 1; i < N; ++i)
            {
                LOG[i] = (i & (i - 1)) ? LOG[i - 1] : LOG[i - 1] + 1;
            }
        }

        void initRMQ()
        {
            initLOG();
            int n = size;
            int limit;
            for (int i = 0; i < n; ++i)
            {
                dp[i][0] = height[i];
            }
            for (int j = 1; j <= LOG[n]; ++j)
            {
                limit = (n - (1 << j));
                for (int i = 0; i <= limit; ++i)
                {
                    dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
                }
            }
        }

        int LCP(int a, int b)
        {
            int t;
            a = Rank[a];
            b = Rank[b];
            if (a > b)
            {
                swap(a, b);
            }
--b;
            t = LOG[b - a + 1];
            return min(dp[a][t], dp[b - (1 << t) + 1][t]);
        }

        bool check(int k, int n)
        {
            memset(cnt, 0, sizeof(cnt));
            memset(MAXS, -1, sizeof(MAXS));
            memset(MINS, inf, sizeof(MINS));
            cnt[pos[sa[1]]] = 1;
            MAXS[pos[sa[1]]] = MINS[pos[sa[1]]] = sa[1];
            for (int i = 1; i < size; ++i)
            {
                if (height[i] >= k)
                {
                    ++cnt[pos[sa[i + 1]]];
                    MAXS[pos[sa[i + 1]]] = max(MAXS[pos[sa[i + 1]]], sa[i + 1]);
                    MINS[pos[sa[i + 1]]] = min(MINS[pos[sa[i + 1]]], sa[i + 1]);
                }
                else
                {
                    bool flag = 1;
                    for (int j = 1; j <= n; ++j)
                    {
                        if (cnt[j] < 2)
                        {
                            flag = 0;
                            break;
                        }
                        else if (MAXS[j] - MINS[j] < k)
                        {
                            flag = 0;
                            break;
                        }
                    }
                    if (flag)
                    {
                        return 1;
                    }
                    memset(cnt, 0, sizeof(cnt));
                    memset(MAXS, -1, sizeof(MAXS));
                    memset(MINS, inf, sizeof(MINS));
                    cnt[pos[sa[i + 1]]] = 1;
                    MAXS[pos[sa[i + 1]]] = MINS[pos[sa[i + 1]]] = sa[i + 1];
                }
            }
            return 0;
        }

        void solve(int n)
        {
            int l = 1, r = size, mid, ans = 0;
            while (l <= r)
            {
                mid = (l + r) >> 1;
                if (check(mid, n))
                {
                    ans = mid;
                    l = mid + 1;
                }
                else
                {
                    r = mid - 1;
                }
            }
            printf("%d\n", ans);
        }
}SA;

char buf[10010];

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n;
        scanf("%d", &n);
        SA.clear();
        int len, maxs = 0, cnt = 0;
        for (int i = 1; i <= n; ++i)
        {
            scanf("%s", buf);
            len = strlen(buf);
            for (int j = 0; j < len; ++j)
            {
                maxs = max(maxs, (int)buf[j]);
                SA.insert((int)buf[j]);
                pos[cnt++] = i;
            }
            SA.insert((int)'z' + i);
            pos[cnt++] = 0;
            maxs = max(maxs, (int)'z' + i);
        }
        SA.getsa(maxs + 1);
        SA.getheight();
        SA.solve(n);
    }
    return 0;
}
无监督学习与互信息 在机器学习中,获取大量高质量标注数据成本高昂。为解决此问题,无监督学习利用丰富的无标注数据成为研究重点。其中,互信息是衡量两个随机变量之间依赖关系的关键指标,能够捕捉非线性统计关联,非常适合处理非结构化数据。通过最大化神经网络中变量间的互信息,可以有效地从无标注数据中提取有用信息,提升模型在下游任务(如分类)的性能。互信息与熵密切相关,其值等于联合分布与边缘分布乘积间的KL散度,也可通过熵与条件熵的差值得出,具有对称性,并反映了已知一个变量后另一个变量不确定性的减少。 阅读详情

相关推荐

STK12与Python联合仿真(一):环境搭建

STK仿真python接口,安装与测试

qq_42635142的博客 1万+

SPOJ 220 后缀数组

简略题意:每个字符串中至少出现两次,且不重叠的最长子串先将nn个字符串连接起来,二分答案tt,用tt分组之后看同一组的是否出现在所有串中至少两次,且在每个原串中的最大最小sa[i]−sa[j]>=ksa[i]-sa[j]>=k。其实只要同时存在最大最小位置,即出现了至少两次。#include <iostream> #include <cstring> #include <map> #include

即使摸爬滚打,满身泥泞,我也要前进 323

three.js开发3D地图记录(二)

添加地图点击事件,点击区域,地图区域改变颜色并浮起来。

anwebDesigner的博客 1694

SPOJ 220 Relevant Phrases of Annihilation (后缀数组)

题目大意: 求在m个串中同时出现两次以上且不覆盖的子串的长度。 思路分析: 二分答案,然后check是否满足,判断不覆盖的方法就是用up down 来处理边界。 #include #include #include #include #include #include #define maxn 110005 using namespace std; char

Jinx Jinx again 826

【多模态融合】TransFusion学习笔记(1)

工作上主要还是以纯lidar的算法开发,部署以及系统架构设计为主。对于多模态融合(这里主要是只指Lidar和Camer的融合)这方面研究甚少。最近借助和朋友们讨论论文的契机接触了一下这方面的知识,起步是晚了一点,但好歹是开了个头。下面就借助TransFusion论文及其开源代码来串一串这方面的知识。这个很好理解,参考FPointNet网络图示。就是利用现有的2D检测器在图像上提取2D初始框,根据Camera成像原理,捕获2D框视锥内的点云,再利用点云分类模型(如:PointNet)做进一步分类。

4961

carsim与simulink联合仿真学习笔记(二)——使用C-class车模做driver model仿真(5 driver sensors)

Driver model 在carsim的Simulink库中自带外部驾驶员模型,打开后如图所示: 然后打开carsim中对应的数据集,如图所示: 具体仿真步骤不在赘述,注意到这里选择的是E-Class车模,那么如果我想选择C-Class车型进行仿真呢?点三角选择车型可以看到: 马赛克部分是我后来建的,如过没有使用过是没有马赛克部分的。那么既然这里没有C-class,又该怎么办呢? 创建C-...

xufuqiang2017的博客 4117

spoj220 每个字符串至少出现两次且不重叠的最长子串(后缀数组)

#include #include #include #include #include #include #include //spoj220 每个字符串至少出现两次且不重叠的最长子串(后缀数组) using namespace std; #define maxn 200010 using namespace std; int wa[maxn

u012432475的专栏 482

el-upload自定义上传dwg/dxf文件并且携带额外参数(CAD)

需求:需要使用el-upload自定义上传cad的图片或普通图片,这边需要判断区分下,以及上传后清空上传文件列表。

请叫我欧皇!的博客 1535

spoj 220 PHRASES - Relevant Phrases of Annihilation(后缀数组)

PHRASES - Relevant Phrases of Annihilation no tags  You are the King of Byteland. Your agents have just intercepted a batch of encrypted enemy messages concerning the date of the planned a

clover_hxy的博客 558

深入解析线性反馈移位寄存器(LFSR)的工作原理与实现

本文深入解析了线性反馈移位寄存器(LFSR)的核心原理与实现方法。通过生动的比喻和详细的步骤拆解,阐述了LFSR如何通过反馈多项式和移位操作生成伪随机序列,并对比了斐波那契型与伽罗瓦型两种硬件结构。文章还涵盖了LFSR在数字电路测试、通信扰码及快速伪随机数生成等关键应用场景,同时指出了其在密码学中的局限性,并提供了Python和C语言的高效实现代码示例。

weixin_29007243的博客 545

GLM-4本地部署的实战教程

本文主要介绍了GLM-4-9B本地部署的实战教程,希望对学习和使用大模型的同学们有所帮助。 文章目录 1. 前言 2. 配置环境 2.1 安装虚拟环境 2.2 安装依赖库 2.3 下载模型文件 3. 运行glm-4-9b-chat

herosunly的博客 25万+

SPOJ220:Relevant Phrases of Annihilation(后缀数组)

Description You are the King of Byteland. Your agents have just intercepted a batch of encrypted enemy messages concerning the date of the planned attack on your island. You immedietaly send for

ACM!荣耀之路! 1595

【25届数字IC秋招总结】面试经验10——紫光同芯

25届数字ic面试记录——紫光同芯

lalala0635的博客 862

SPOJ 220. Relevant Phrases of Annihilation(后缀数组多次不重叠子串)

题目大意:给定N个串,求每个串至少出现两次的最长子串。 解题思路:每个字符串至少出现两次且不可重叠的最长子串:二分枚举长度后在同一分组中对每一个字符串保留一个最小的位置和一个最大的位置,最后查看是否每个串在同一组中都有至少两个后缀,并且后缀的坐标差大于枚举的长度。 POJ Problem Set (classical) 220. Relevant Phrases of Annihil

I am a slow walker, but I never walk backwards! 1287

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

【SPOJ 220】Relevant Phrases of Annihilation

http://www.spoj.com/problems/PHRASES/ 求出后缀数组然后二分。 因为有多组数据,所以倍增求后缀数组时要特判是否越界。 二分答案时的判断要注意优化! 时间复杂度\(O(TnL\log L)\),L为字符串总长度。 #include<cstdio> #include<cstring> #include<algorithm&gt...

as2886089的博客 121

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

SPOJ 220 Relevant Phrases of Annihilation(后缀数组)

题目链接:http://www.spoj.pl/problems/PHRASES/ 题意:给定n个字符串,求在每个字符串中至少出现两次且不重叠的最长字串。 思路:先将n个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求sa和height数组。然后二分答案,将后缀分组。判断的时候,要看是否有一组后缀在每个原来的字符串中至少出现两次,并且在每个原来的字符串中,后缀的起始位置的最大值与...

weixin_34161029的博客 116

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

spoj 220 Relevant Phrases of Annihilation (后缀数组应用)

题意: 给出n个串,求着n个串最长公共子串,并且子串在各个串中至少重复两次,并且不能重叠的重复。 题解: 这里又用到了后缀的分组,我们首先拼接n个串然后跑一边后缀数组,二分长度,接着根据height分组,然后统计每组的后缀所属的串的个数,并且要判断是否存在至少重复两次的子串且不重叠,统计所属串的个数可以用set存,然后获取size即可,对于后一个问题,我们将每次分得的组统计所属每个串的SA[

ACM之梦 677

SPOJ 220 PHRASES Relevant Phrases of Annihilation 后缀数组

题目大意: 就是现在给出T组测试数据(T 对于每一组, 求在所给的所有串都出现了至少两次的子串的最大长度, 每个串中出现的两次不能有重叠部分 大致思路: 很明显的后缀数组利用height数组进行分组的题 刚开始的时候没有考虑出现的两次不重合(没仔细读题以为可以...) WA了2发= = 具体细节见代码: 代码如下: Result  :  Accepted

Gatevin的专栏 690

spoj220 Relevant Phrases of Annihilation

题意是给n个串,求出一个最长的子串在每个串中至少出现两次。直接二分答案来判断,因为题目里要求在一个串中,两次出现的位置不能有交叉,所以这要想办法特殊处理下,大体的思路还是循环height数组,按>=当前二分长度来分组,处理一组时,用两个数组分别记录一下本组后缀在各个串中出现的最大位置和最小位置,那么如果某一个串上他的最大位置和最小位置的差大于等于当前长度了,就是两个没有交叉的匹配了。      

Broken Wings 719

【SPOJ 220】 PHRASES - Relevant Phrases of Annihilation

【链接】h在这里写链接 【题意】 给你n(n<=10)个字符串。 每个字符串长度最大为1e4; 问你能不能找到一个子串. 使得这个子串,在每个字符串里面都不想交出现了至少两次; 输出子串的最长值。 【题解】 后缀数组题; 把n个字符串,通过一个连接符连接在一起。 然后求其...

160

SPOJ 220 PHRASES - Relevant Phrases of Annihilation(后缀数组)

题意: 询问在每个字符串都出现两次且不重叠的最长子串的长度。 题解: 利用后缀数组分组的性质,求出每一组有没有满足条件的子串,然后二分答案,其中在原字符串中出现两次可以用这个字符串里max(sa[i])−min(sa[i])max(sa[i])-min(sa[i])max(sa[i])−min(sa[i])解决,不重叠就是判断这个maxmaxmax是不是大于等于mid,最后判断是否是每个字符串都满...

qq_43544481的博客 168

SPOJ220 Relevant Phrases of Annihilation(后缀数组)

引用罗穗骞论文中的话: 先将n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组。然后二分答案,再将后缀分组。判断的时候,要看是否有一组后缀在每个原来的字符串中至少出现两次,并且在每个原来的字符串中,后缀的起始位置的最大值与最小值之差是否不小于当前答案(判断能否做到不重叠,如果题目中没有不重叠的要求,那么不用做此判断)。这个做法的时间复杂度为O(nlogn...

Nobel7889的专栏 172

spoj 220 Relevant Phrases of Annihilation

You are the King of Byteland. Your agents have just intercepted a batch of encrypted enemy messages concerning the date of the planned attack on your island. You immedietaly send for the Bytelandian C...

weixin_30539625的博客 113

[SPOJ220]PHRASES - Relevant Phrases of Annihilation(后缀数组+二分)

题目描述传送门 题意:给定 n 个字符串,求在每个字符串中至少出现两次且不重叠的最长子串。题解先将 n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组。然后二分答案,再将后缀分组。判断的时候,要看是否有一组后缀在每个原来的字符串中至少出现两次,并且在每个原来的字符串中,后缀的起始位置的最大值与最小值之差是否不小于当前答案(判断能否做到不重叠)。代码#include<al

zyf2000 844

SPOJ 220 . Relevant Phrases of Annihilation(后缀数组)

SPOJ 220 . Relevant Phrases of Annihilation(后缀数组) 题意:给你N个串,要你在这N个串中找出这样一个最长的子串长度.该串在任意一个串中至少出现了2次,并且不重叠的. 分析: 罗穗骞《后缀数组——处理字符串的有力工具》例题.        首先依然连接所有串,并且加上分隔符.然后依然是二分答案,看看长为limit的这个串是否存在.在每个height

code 1212
上一篇: SPOJ687---REPEATS - Repeats(后缀数组+RMQ)
下一篇: POJ3581---Sequence(后缀数组)
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值