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 ...
随机推荐
- 设计模式课程 设计模式精讲 22-2 备忘录模式coding
1 代码演练 1.1 代码演练1 1 代码演练 1.1 代码演练1 需求: 网站笔记需要存储快照,能实现回退的功能. 注意: a 设计的时候,可以分为笔记类,笔记快照类和 笔记快照管理类 三个类. ...
- Python爬虫教程-爬取5K分辨率超清唯美壁纸源码
简介 壁纸的选择其实很大程度上能看出电脑主人的内心世界,有的人喜欢风景,有的人喜欢星空,有的人喜欢美女,有的人喜欢动物.然而,终究有一天你已经产生审美疲劳了,但你下定决定要换壁纸的时候,又发现网上的壁 ...
- 如何优雅地根治null值引起的Bug!
本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...
- FTP的vsftpd.conf含义
# 设置为YES时vsftpd以独立运行方式启动,设置为NO时以xinetd方式启动 #(xinetd是管理守护进程的,将服务集中管理,可以减少大量服务的资源消耗) listen=YES # 同上,如 ...
- 【快学springboot】使用springboot发送邮件
前言 在实际项目中,经常需要用到邮件通知功能.比如,用户通过邮件注册,通过邮件找回密码等:又比如通过邮件发送系统情况,通过邮件发送报表信息等等,实际应用场景很多.这篇文章,就教大家通过springbo ...
- python如何画三维图像?
python三维图像输出的代码如下所示:#画3D函数图像输出from mpl_toolkits.mplot3d import Axes3Dfrom matplotlib import cmimport ...
- 1_02_MSSQL课程_T_SQL语句入门
1.->全名:结构化查询语言(Structured Query Language) 关系数据库管理系统的标准语言. ->SQL主要分为三种语言:DML\DDL\DCL DDL(数据定 ...
- mysql视图初探
mysql视图初探 官方例子如下,从官方的例子就可以看出来视图就是提供一种快捷查询.用视图来查询一些常用的结果. mysql> help create view; Name: 'CREATE V ...
- easyui学习索引页
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>复 ...
- Linux环境安装Golang
命令行安装 yum install golang 默认安装目录/usr/lib/golang/ (不同系统不一样,可通过搜索golang关键字查找: find / -name golang) 卸载 ...