和上一个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的更多相关文章

  1. POJ-3450 Corporate Identity (KMP+后缀数组)

    Description Beside other services, ACM helps companies to clearly state their “corporate identity”, ...

  2. hdu 2328 Corporate Identity(kmp)

    Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...

  3. hdu2328 Corporate Identity【string库使用】【暴力】【KMP】

    Corporate Identity Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. hdu2328 Corporate Identity 扩展KMP

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  5. (KMP 暴力)Corporate Identity -- hdu -- 2328

    http://acm.hdu.edu.cn/showproblem.php?pid=2328 Corporate Identity Time Limit: 9000/3000 MS (Java/Oth ...

  6. hdu2328 Corporate Identity

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题目: Corporate Identity Time Limit: 9000/3000 MS (J ...

  7. POJ3450 Corporate Identity 【后缀数组】

    Corporate Identity Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7662   Accepted: 264 ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  9. POJ3450 Corporate Identity —— 后缀数组 最长公共子序列

    题目链接:https://vjudge.net/problem/POJ-3450 Corporate Identity Time Limit: 3000MS   Memory Limit: 65536 ...

随机推荐

  1. luogu P2774 方格取数问题

    有限制的问题,显然考虑全选再根据限制去掉的想法较优,我们发现一个点四周的点受限,其x或者y差一,也就是说奇偶性不同,那我们可以将其分成白点和黑点,就变成了最小割的问题,将每个白点向受限制的黑点连边,c ...

  2. Firefox 的 hack 及 问题

    hack: @-moz-document url-prefix(){ #selector{ display: flex; justify-content: space-between; } } 问题一 ...

  3. 121、Java面向对象之使用this关键字明确地表示访问类中的属性

    01.代码如下: package TIANPAN; class Book { private String title; private double price; public Book(Strin ...

  4. jetson nano 安装 snowboy 遇到的问题及处理

    Snowboy 是 KITT.AI 开发的一个高度可定制的热词检测引擎,当笔者的 jetson nano 加上话筒后,就立马尝试安装,但在安装过程中却发生了错误,所以把处理方式记录了下来以作备忘. 首 ...

  5. Fescar分布式事务实现原理解析探秘

    前言 fescar发布已有时日,分布式事务一直是业界备受关注的领域,fescar发布一个月左右便受到了近5000个star足以说明其热度.当然,在fescar出来之前,已经有比较成熟的分布式事务的解决 ...

  6. JavaScript图形实例:图形的平移和对称变换

    1.1  六瓣花平移变换 平移变换是指图形从一个位置到另一个位置所作的直线移动.如果要把一个位于P(x,y)的点移到新位置P’(x’,y’),如图1,则只要在原坐标上加上平移距离Tx和Ty即可. 即  ...

  7. C#用SQLDMO操作数据库----转载

    C#用SQLDMO操作数据库 sqldmo.dll是随sql server2000一起发布的.sqldmo.dll自身是一个com对象 sqldmo(sql distributed managemen ...

  8. (十四)登陆注册 逻辑二 前端globalData的使用 和 Storage

                        我们在点击登录的时候  成功之后跳转到home 一 在全局的app.js里会有一个 globalData 因为还有其他页面也要使用 共有的数据 所有用到  gl ...

  9. ASP.NET MVC 4 中Razor 视图中JS无法调试 (重要)

    谷歌浏览器,firefox,IE 都可以 1.首先检查IE中这2个属性是否勾选了. 2.选择IE浏览器进行调试,调试方法有2种 A:采用debugger;的方法,如下图所示: 这时不用调试断点就会在d ...

  10. PAT A1025 pat ranking

    有n个考场,每个考场都有若干数量个考生,现给出各个考场中考生的准考证号和分数,要求将所有考生的分数从高到低排序,并输出 #include<iostream> #include<str ...