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 ...
随机推荐
- windows 批量杀进程 类似pkill
轉:http://blog.sina.com.cn/s/blog_55fb522f0100whki.html 1.开始-运行(或win+R),输入cmd,打开命令行模式: 2.输入tasklist,可 ...
- Python正则表达式就是这么简单【新手必学】
一前言本篇文章带大家快速入门正则表达式的使用,正则表达式的规则不仅适用python语言,基本大多数编程语言都适用,在日常使用中极为广泛,读者们有必要学好正则表达式.看完这篇文章,读者们要理解什么是正则 ...
- C. Gas Pipeline DP
C. Gas Pipeline time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Linux中用systemctl命令管理服务
systemctl start foo.service 启动服务systemctl restart foo.service 重启服务systemctl stop foo.service 停止服务sys ...
- Hadoop的伪分布式安装和部署的流程
1.准备工作 下载一些用到的命令 yum install -y vim yum install -y lrzsz yum install net-tools 目录约定 /opt #工作目录 /opt/ ...
- Python可视化 | Seaborn包—heatmap()
seaborn.heatmap()的参数 seaborn.heatmap(data, vmin=None, vmax=None, cmap=None, center=None, robust=Fals ...
- 手写MQ框架(四)-使用netty改造梳理
一.背景 书接上文手写MQ框架(三)-客户端实现,前面通过web的形式实现了mq的服务端和客户端,现在计划使用netty来改造一下.前段时间学习了一下netty的使用(https://www.w3cs ...
- SSH框架系列:Spring读取配置文件以及获取Spring注入的Bean
分类: [java]2013-12-09 16:29 1020人阅读 评论(0) 收藏 举报 1.简介 在SSH框架下,假设我们将配置文件放在项目的src/datasource.properties路 ...
- pyhon 内置函数
chr() asci码 dir() 目录,显示目录. divmod(10,3) 返回商和余数 例如 (3, 1) 返回的为一个元组 可以用于分页 enumerate() ...
- Lesson 6 The sporting spirit
How does the writer describe sport at the international level? I am always amazed when I hear people ...