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 ...
随机推荐
- Python简单程序爬取天气信息,定时发邮件给朋友【高薪必学】
前段时间看到了这个博客.https://blog.csdn.net/weixin_45081575/article/details/102886718.他用了request模块,这不巧了么,正好我刚用 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:悬停表格
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- shell脚本中执行sql脚本(mysql为例)
1.sql脚本(t.sql) insert into test.t value ("LH",88); 2.shell脚本(a.sh 为方便说明,a.sh与t.sql在同一目 ...
- ZCGL大数据平台性能优化
对HBase数据库建索引 参见:基于Phoenix对HBase建索引 https://www.cnblogs.com/ratels/p/11203313.html 将HBase访问微服务整合到模块 ...
- idea中的Storm1.1.1工程自定义日志级别
在idea中跑storm工程时,因为Storm中的日志级级别默认为INFO,控制台总是打印出很多没用的INFO级别的日志,导致我自己在代码中的sout内容看不清楚. 于是想着自定义日志的打印级别为WA ...
- 二、Navicat、IDEA、nopad、eclipse、excle工具使用、问题、快捷键
1.Navicat工具: 目的:本地数据库与远程数据库之间数据导入导出 步骤1:文件--新建oracle链接/mysql的连接 步骤2:工具-选项:将本地oracle的bin\oci.dll 的路径复 ...
- springboot中文官方文档
springboot中文官方文档 https://www.breakyizhan.com/springboot/3028.html spring框架 https://www.breakyizhan.c ...
- centos查找文件\目录\内容命令
1.查找文件 find / -name 'php.ini'12.查找目录 find / -name 'path' find / -name 'path' -type d13.查找内容 find . | ...
- Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3
前端导入静态页面的时候有一个报错,主要问题是冲突了 Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or hi ...
- 题解 loj3050 「十二省联考 2019」骗分过样例
CASE \(1\sim 3\) \(n\)组测试数据,每次输入一个数\(x\),求\(19^x\). 测试点\(1\),\(x=0,1,\dots n-1\),可以直接递推. 测试点\(2\)要开l ...