hdu 2328 Corporate Identity(kmp)
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.
题意&思路:hdu 1238 数据的加强版 需要注意优化点已在代码处标记
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define ll long long int
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int n;
string s[];
int nextt[];
void getnext(string s){
nextt[]=;
int len=s.length();
for(int i=,j=;i<=len;i++){
while(j>&&s[i-]!=s[j]) j=nextt[j];
if(s[i-]==s[j]) j++;
nextt[i]=j;
}
}
bool kmp(string t,string p){
int len1=p.length();
int len2=t.length();
for(int i=,j=;i<=len1;i++){
while(j>&&p[i-]!=t[j]) j=nextt[j];
if(p[i-]==t[j]) j++;
if(j==len2) return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
while(cin>>n&&n){
for(int i=;i<n;i++)
cin>>s[i];
int len=s[].length();
string ans="";
for(int i=len;i>=;i--){
for(int j=;j<=len-i;j++){
string temp=s[].substr(j,i);
getnext(temp);
bool f=;
for(int k=;k<n;k++)
if(!kmp(temp,s[k])){
f=;
break; //碰到假就弹出
}
if(f){
if(ans.size()<temp.size()) ans=temp;
else if(ans.size()==temp.size()) ans=min(ans,temp);
}
}
}
if(ans.size()<) cout<<"IDENTITY LOST"<<endl;
else cout<<ans<<endl; }
return ;
}
hdu 2328 Corporate Identity(kmp)的更多相关文章
- HDU - 2328 Corporate Identity(kmp+暴力)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题意:多组输入,n==0结束.给出n个字符串,求最长公共子串,长度相等则求字典序最小. 题解:(居 ...
- POJ-3450 Corporate Identity (KMP+后缀数组)
Description Beside other services, ACM helps companies to clearly state their “corporate identity”, ...
- HDU 2328 POJ 3450 KMP
题目链接: HDU http://acm.hdu.edu.cn/showproblem.php?pid=2328 POJhttp://poj.org/problem?id=3450 #include ...
- POJ 3450 Corporate Identity kmp+最长公共子串
枚举长度最短的字符串的所有子串,再与其他串匹配. #include<cstdio> #include<cstring> #include<algorithm> #i ...
- POJ 3450 Corporate Identity KMP解决问题的方法
这个问题,需要一组字符串求最长公共子,其实灵活运用KMP高速寻求最长前缀. 请注意,意大利愿父亲:按照输出词典的顺序的规定. 另外要提醒的是:它也被用来KMP为了解决这个问题,但是很多人认为KMP使用 ...
- (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 扩展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 ...
- POJ 题目3450 Corporate Identity(KMP 暴力)
Corporate Identity Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5493 Accepted: 201 ...
随机推荐
- Composer安装与使用
Composer是PHP中用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer会帮你安装这些依赖的库文件. Windows ...
- PDO连接mysql数据库加载慢
今天在使用PDO连接mysql操作数据库的时候,发现速度特别慢,都1~2s的时间,不知道怎么回事,后来一步一步排除到new PDO 导致过慢的原因, 这个尴尬了...,调试了半天都没想到问下度娘,才知 ...
- windows10企业版2016长期服务版激活
win10 2016 长期服务版的ISO文件中本身就带有KMS激活KEY,不用输入任何KEY,连接网络进入CMD,只要输入:slmgr /skms kms.digiboy.irslmgr /ato这两 ...
- python之路--subprocess,粘包现象与解决办法,缓冲区
一. subprocess 的简单用法 import subprocess sub_obj = subprocess.Popen( 'dir', #系统指令 shell=True, #固定方法 std ...
- kubernetes常用命令
#.查询信息 kubectl get [需要查询的服务] node 节点componentstatuses 简写 cs 组件状态namespaces 简写 ns 名命空间pod pod信息 添加 ...
- ubuntu 完全卸载mysql
卸载 sudo apt-get --purge remove mysql-common -y sudo apt-get --purge remove mysql* -y sudo apt-get au ...
- c++ string类型的定义及方法
1.c++ 有两种风格的字符串形式 c风格字符串 定义及初始化 char a[]={'h','e','l','l','o','\0'} 或者 char a[]="hello&quo ...
- codeforces478C
Table Decorations CodeForces - 478C 你有r个红的,g个绿的和b个蓝的气球.要为宴会布置一张桌子,你恰好需要三个气球.附在桌子上的三个气球不应该有相同的颜色.如果我们 ...
- HTC Vive 基础入门 基于Unity3D引擎
任务2: 01-概述 07:08 任务3: 02-HTC Vive设备的安装 08:33 任务4: 03-下载Steam与SteamVR 03:05 任务5: 04-使用Steam VR 调试设备 1 ...
- ScheduledThreadPoolExecutor 吞异常
线程挂掉不一定会输出日志到控制台,比如ScheduledThreadPoolExecutor,如果在执行的任务中有未捕获的异常抛出,就行停止调度,没有任何错误输出到控制台或日志文件.在项目中这会导致一 ...