hdu2328 Corporate Identity
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2328
题目:
Corporate Identity
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1599 Accepted Submission(s): 614
After several other proposals, it was decided to take all existing trademarks and find the longest common sequence of letters that is contained in all of them. This sequence will be graphically emphasized to form a new logo. Then, the old trademarks may still be used while showing the new identity.
Your task is to find such a sequence.
After the last trademark, the next task begins. The last task is followed by a line containing zero.
aabbaabb
abbababb
bbbbbabb
2
xyz
abc
0
IDENTITY LOST
思路:kmp+暴力枚举
#include <cstdio>
#include <cstring>
#include <iostream> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
const double eps=1e-;
const int K=1e6+;
const int mod=1e9+; int nt[K];
char sa[][],sb[];
void kmp_next(char *T,int *next)
{
next[]=;
for(int i=,j=,len=strlen(T);i<len;i++)
{
while(j&&T[i]!=T[j]) j=next[j-];
if(T[i]==T[j]) j++;
next[i]=j;
}
}
int kmp(char *S,char *T,int *next)
{
int ans=;
int ls=strlen(S),lt=strlen(T);
for(int i=,j=;i<ls;i++)
{
while(j&&S[i]!=T[j]) j=next[j-];
if(S[i]==T[j]) j++;
if(j==lt) ans++;
}
return ans;
}
int cmp(char *sb,int si,int st,int len)
{
for(int i=;i<len;i++)
if(sb[si+i]<sb[st+i])
return -;
else if(sb[si+i]>sb[st+i])
return ;
return ;
}
int main(void)
{
int t,n;
while(scanf("%d",&n)&&n)
{
for(int i=;i<=n;i++)
scanf("%s",sa[i]);
int len,st,se;
len=strlen(sa[]);
st=,se=-;
for(int i=;i<len;i++)
{
for(int j=i;j<len;j++)
{
sb[j-i]=sa[][j],sb[j-i+]='\0';
int ff=;
kmp_next(sb,nt);
for(int k=;k<=n&&ff;k++)
if(!kmp(sa[k],sb,nt))
ff=;
if(ff&&j-i>se-st)
st=i,se=j;
else if(ff&&j-i==se-st&&cmp(sa[],i,st,j-i+)<)
st=i,se=j;
}
}
if(se-st+<)
printf("IDENTITY LOST\n");
else
{
for(int i=st;i<=se;i++)
printf("%c",sa[][i]);
printf("\n");
} }
return ;
}
hdu2328 Corporate Identity的更多相关文章
- 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 ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- [HDU2328]Corporate Identity(后缀数组)
传送门 求 n 个串的字典序最小的最长公共子串. 和 2 个串的处理方法差不多. 把 n 个串拼接在一起,中间连上一个没有出现过的字符防止匹配过界. 求出 height 数组后二分公共子串长度给后缀数 ...
- 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 ...
- (KMP 暴力)Corporate Identity -- hdu -- 2328
http://acm.hdu.edu.cn/showproblem.php?pid=2328 Corporate Identity Time Limit: 9000/3000 MS (Java/Oth ...
- POJ3450 Corporate Identity 【后缀数组】
Corporate Identity Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7662 Accepted: 264 ...
- POJ3450 Corporate Identity —— 后缀数组 最长公共子序列
题目链接:https://vjudge.net/problem/POJ-3450 Corporate Identity Time Limit: 3000MS Memory Limit: 65536 ...
随机推荐
- mysql解决乱码问题
进入mysql(mysql -u root -p),查看当前数据库字符集(status;) 刚开始是latin1,所以乱码. vim /etc/my.cnf 两个节点添加如下: [client]def ...
- hdu 1520(简单树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 思路:dp[u][0]表示不取u的最大价值,dp[u][1]表示取u的最大价值,于是有dp[u] ...
- jboss eap 6.4 部署 从weblogic迁移
从weblogic10.3像jboss 6.4项目迁移,遇到的一些问题: 因为使用weblogic可以自定义公共的war包库,在使用jboss中,也采取项目依赖公共库的方式: 1.jboss中使用公共 ...
- 1-2、superset国际化
最近由于工作需要研究开源可视化项目superset,由于其国际化做不怎么好,故而记录下国际化的过程,本篇本着『授人以鱼不如授人以渔』的原则,只叙述国际化的过程及方法,不提供直接的国际化文件. 为了方便 ...
- Android弹出一项权限请求
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(ena ...
- JSP状态管理 及 Cookie实例
HTTP协议的无状态性 无状态是指,当浏览器发送请求给服务器的时候,服务器响应客户端的请求. 但是当同一个浏览器再次发送请求给了服务器的时候,服务器并不知道它就是刚才那个浏览器. 简单地说,就是服务器 ...
- Javascript通过bind()掌控this
Javascript通过bind()掌控this: http://blog.csdn.net/rznice/article/details/26134201 bind能为我们做些什么,同时它的好处在哪 ...
- Android中的 style 和 theme
通过设置 view 控件的属性,达到设置android UI的目的,如果某些 属性值复用率很高,可以考虑将属性单独声明在 style中,这样就可以达到复用的效果. 一.style Style 概念:A ...
- vue下使用echarts折线图及其横坐标拖拽功能
vue页面中使用折线图,并且有时间段筛选.因此就需要用到横坐标的拖拽功能. 界面效果如下: 现在来看这个效果的实现代码: drawLine() { let that = this, lineDate ...
- C++的全部目标就是最优化资源的利用,以人付出更多为代价。Python刚好是另一个极端(Bjarne就说,一个人至少应该掌握两种计算机语言)
说 C++ 反人类,是如果把 C++ 看作人(程序员)和资源(电子系统)的桥梁,他的全部目标就是最优化资源的利用,以人付出更多为代价.Python刚好是另一个极端.做好两个一起学.Bjarne就说,一 ...