poj3405 Corporate Identity
和上一个1226一样吧,这个还不用翻转
然而本蒟蒻还是写不对,WA一片天,不知道自己搞什么,自从去了长沙感觉就是坑啊
while(1) iq--;
/*#include <cstdio>
#include <iostream>
#include <cstring>
#define N 100005
#define LL long long
#define eps 1e-8
using namespace std;
inline int ra()
{
int x=0,f=1; char ch=getchar();
while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
} const int M=4233;
const int maxn=4000*233*3; int sa[2][maxn],rank[2][maxn],height[maxn],v[M+5];
char ans[205];
int n,len,id[maxn],p,q,a[maxn];
bool vis[M]; void cal_sa(int sa[maxn], int rank[maxn], int Sa[maxn], int Rank[maxn], int k)
{
for (int i=1; i<=n; i++) v[rank[sa[i]]]=i;
for (int i=n; i>=1; i--) if (sa[i]>k) Sa[v[rank[sa[i]-k]]--]=sa[i]-k;
for (int i=n-k+1; i<=n; i++) Sa[v[rank[i]]--]=i;
for (int i=1; i<=n; i++) Rank[Sa[i]]=Rank[Sa[i-1]]+(rank[Sa[i]]!=rank[Sa[i-1]] || rank[Sa[i]+k]!=rank[Sa[i-1]+k]);
}
void get_height()
{
int k=0;
for (int i=1; i<=n; i++)
{
if (rank[p][i]==1) height[1]=0;
else
{
int j=sa[p][rank[p][i]-1];
while (a[j+k]==a[i+k]) k++;
height[rank[p][i]]=k;
if (k) k--;
}
}
}
void work()
{
for (int i=1; i<=n; i++) v[a[i]]++;
for (int i=1; i<=M; i++) v[i]+=v[i-1];
for (int i=1; i<=n; i++) sa[p][v[a[i]]--]=i;
for (int i=1; i<=n; i++) rank[p][sa[p][i]]=rank[p][sa[p][i-1]]+(a[sa[p][i]]!=a[sa[p][i-1]]);
for (int k=1; k<n; k<<=1,swap(p,q)) cal_sa(sa[p],rank[p],sa[q],rank[q],k);
get_height();
}
bool check(int L)
{
int cnt=0;
memset(vis,0,sizeof(vis));
for (int i=2; i<=n; i++)
{
if (height[i]<L)
{
cnt=0;
memset(vis,0,sizeof(vis));
continue;
}
if (!vis[id[sa[p][i-1]]]) vis[id[sa[p][i-1]]]=1,cnt++;
if (!vis[id[sa[p][i]]]) vis[id[sa[p][i]]]=1,cnt++;
if (cnt==len)
{
for (int j=0; j<L; j++)
ans[j]=a[sa[p][i]+j];
return 1;
}
}
return 0;
}
int main(int argc, char const *argv[])
{
while (scanf("%d",&n) && n)
{
len=0;
memset(v,0,sizeof(v));
for (int i=1; i<=n; i++)
{
char ch[205];
scanf("%s",ch+1);
for (int j=1; j<=strlen(ch+1); j++) a[++len]=ch[j],id[len]=i;
a[++len]=150+i; id[len]=i;
}
swap(n,len);
work();
// for (int i=1; i<=n; i++) cout<<height[i]<<" "<<id[sa[p][i]]<<endl;
int l=1,r=205; bool flag=0;
while (l<=r)
{
int mid=l+r>>1;
if (check(mid)) flag=1,l=mid+1;
else r=mid-1;
}
if (flag) printf("%s\n",ans);
else puts("IDENTITY LOST");
}
return 0;
}*/ #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 888888
int t1[maxn],t2[maxn],c[maxn],sa[maxn],rank[maxn],height[maxn];
bool cmp(int *r, int a, int b, int l)
{
return r[a]==r[b] && r[a+l]==r[b+l];
}
void da(int str[], int n, int m)
{
n++; int *x=t1,*y=t2;
for (int i=; i<m; i++) c[i]=;
for (int i=; i<n; i++) c[x[i]=str[i]]++;
for (int i=; i<m; i++) c[i]+=c[i-];
for (int i=n-; i>=; i--) sa[--c[x[i]]]=i;
for (int j=; j<=n; j<<=)
{
int p=;
for (int i=n-j; i<n; i++) y[p++]=i;
for (int i=; i<n; i++) if (sa[i]>=j) y[p++]=sa[i]-j;
for (int i=; i<m; i++) c[i]=;
for (int i=; i<n; i++) c[x[y[i]]]++;
for (int i=; i<m; i++) c[i]+=c[i-];
for (int i=n-; i>=; i--) sa[--c[x[y[i]]]]=y[i];
swap(x,y);
p=; x[sa[]]=;
for (int i=; i<n; i++) x[sa[i]]=cmp(y,sa[i-],sa[i],j)?p-:p++;
if (p>=n) break;
m=p;
}
int k=; n--;
for (int i=; i<=n; i++) rank[sa[i]]=i;
for (int i=; i<n; i++)
{
if (k) k--;
int j=sa[rank[i]-];
while (str[i+k]==str[j+k]) k++;
height[rank[i]]=k;
}
}
int n,res,a[maxn],id[maxn],vis[];
char s[],ans[];
int check(int k)
{
int cnt=;
memset(vis,,sizeof(vis));
for(int i=;i<=res;i++)
{
if(height[i]<k)
{
memset(vis,,sizeof(vis));
cnt=;
continue;
}
if(!vis[id[sa[i-]]])
vis[id[sa[i-]]]=,cnt++;
if(!vis[id[sa[i]]])
vis[id[sa[i]]]=,cnt++;
if(cnt==n)
{
for(int j=;j<k;j++)
ans[j]=a[sa[i]+j];
ans[k]='\0';
return ;
}
}
return ;
}
int main()
{
while(~scanf("%d",&n),n)
{
res=;
for(int i=;i<n;i++)
{
scanf("%s",s);
int len=strlen(s);
for(int j=;j<len;j++)
a[res]=s[j],id[res++]=i;
a[res]='#'+i;
id[res++]='#'+i;
}
a[res]=;
da(a,res,);
int l=,r=strlen(s),flag=;
while(l<=r)
{
int mid=(l+r)>>;
if(check(mid))
{
flag=;
l=mid+;
}
else r=mid-;
}
if(flag)printf("%s\n",ans);
else printf("IDENTITY LOST\n");
}
return ;
}
poj3405 Corporate Identity的更多相关文章
- POJ-3450 Corporate Identity (KMP+后缀数组)
Description Beside other services, ACM helps companies to clearly state their “corporate identity”, ...
- hdu 2328 Corporate Identity(kmp)
Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...
- hdu2328 Corporate Identity【string库使用】【暴力】【KMP】
Corporate Identity Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu2328 Corporate Identity 扩展KMP
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- (KMP 暴力)Corporate Identity -- hdu -- 2328
http://acm.hdu.edu.cn/showproblem.php?pid=2328 Corporate Identity Time Limit: 9000/3000 MS (Java/Oth ...
- hdu2328 Corporate Identity
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题目: Corporate Identity Time Limit: 9000/3000 MS (J ...
- POJ3450 Corporate Identity 【后缀数组】
Corporate Identity Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7662 Accepted: 264 ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- POJ3450 Corporate Identity —— 后缀数组 最长公共子序列
题目链接:https://vjudge.net/problem/POJ-3450 Corporate Identity Time Limit: 3000MS Memory Limit: 65536 ...
随机推荐
- MyEclipse和Eclipse中常用的快捷键
##########################快捷键分类速查########################## *******常用类********[Ctrl+O] 显示类中方法和 ...
- 「TJOI2013」最长上升子序列
「TJOI2013」最长上升子序列 传送门 这个 \(\text{DP}\) 应该都会撒: \[dp_i = \max_{j < i,a_j < a_i}\left\{dp_j\right ...
- list的三个子类的特点
- vue-cli 初始化项目时开发环境中的跨域问题
最近刚刚完成自己的毕业设计(基于Vue的信息资讯展示与管理平台),于是想整理一下过程遇到的一些问题. 项目基于Vue开发,使用 Vue-cli 初始化项目文件目录时默认占用8080端口,而我又想使用 ...
- 进程管理与SELinux
进程(process): 将程序与进程的总结: 程序 (program):通常为 binary program ,放置在储存媒体中 (如硬盘.光盘.软盘.磁带等), 为实体文 件的型态存在 ...
- 2020 NUC 19级第一次训练赛
感染(low) Description n户人家住在一条直线上,从左往右依次编号为1,2,...,n.起初,有m户人家感染了COVID-19,而接下来的每天感染的人家都会感染他家左右两家的人,问t天后 ...
- Windows系统(服务器)忘记管理员登录密码:
windows sever2003忘记密码:使用老毛桃PE进入然后修改密码,重启即可. windows sever2008忘记密码:可按该网址的方法即可解决:http://www.jb51.net/a ...
- Mybatis入门(六)联查之多对一
Mysql可以联查,但Mybatis也可以联查只是没有MySQL联查的舒服需要配置很多文件. 开始搭建环境: MySQL新建两个表一个Student一个Teacher表: Teacher表: CREA ...
- window进行缩放时左侧菜单高度随之变化
window.onresize = function(){ $(); }
- IdentityServer4专题之二:OpenID介绍
1.基于概念 OpenId是一个以用户为中心的数字身份识别框架,它具有开放.分散.自由等特性.OpenId的创建是基于这样一个概念:我们可以通过URI(或者URL网址)来识别一个网站.同样,我们也可以 ...