Corporate Identity - HDU 2328(多串求共同子串)
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
using namespace std; const int MAXN = ;
const int MAXM = ;
const int oo = 1e9+; struct node
{
int times;
node *next[MAXN];
}; int BuildTrie(node *head, char s[], int x)
{
int i, k, depth = ;
node *P = head; for(i=; s[i]; i++)
{
k = s[i] - 'a';
if(P->next[k] == NULL)
{
if(x != )
break;
P->next[k] = new node();
} P = P->next[k]; if(P->times + >= x)
{///如果此节点是本个串访问过或者上个节点访问过
P->times = x;
depth++;
}
else break;
} return depth;
}
void clearTrie(node *head)
{///销毁树
node *P = head; for(int i=; i<MAXN; i++)
{
if(P->next[i] != NULL)
clearTrie(P->next[i]);
} free(P);
} int main()
{
int i, j, N; while(scanf("%d", &N), N)
{
node *head = new node();
char s[MAXM]={}, ans[MAXM]={}; for(i=; i<N; i++)
{
scanf("%s", s);
for(j=; s[j] != '\0'; j++)
BuildTrie(head, s+j, i);
}
scanf("%s", s); int Max = ; for(j=; s[j] != '\0'; j++)
{
int len = BuildTrie(head, s+j, N);
char p[MAXM] = {}; strncpy(p, s+j, len); if(Max < len || (Max==len && strcmp(ans, p) > ))
strcpy(ans, p), Max = len;
} if(ans[] == )
printf("IDENTITY LOST\n");
else
printf("%s\n", ans); clearTrie(head);
} return ;
}
Corporate Identity - HDU 2328(多串求共同子串)的更多相关文章
- POJ 3450 Corporate Identity (KMP,求公共子串,方法很妙)
http://blog.sina.com.cn/s/blog_74e20d8901010pwp.html我采用的是方法三. 注意:当长度相同时,取字典序最小的. #include <iostre ...
- 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 ...
- POJ-3450 Corporate Identity (KMP+后缀数组)
Description Beside other services, ACM helps companies to clearly state their “corporate identity”, ...
- 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 ...
- POJ3450 Corporate Identity —— 后缀数组 最长公共子序列
题目链接:https://vjudge.net/problem/POJ-3450 Corporate Identity Time Limit: 3000MS Memory Limit: 65536 ...
- hdu2328 Corporate Identity【string库使用】【暴力】【KMP】
Corporate Identity Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- N - Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
随机推荐
- OC - 23.核心动画基础
概述 简介 核心动画提供了一组非常强大的动画API,通过该组API可以高效的实现绝大部分绚丽的动画效果 注意事项 核心动画的操作在子线程中执行,不会阻塞主线程 核心动画直接作用与CALayer对象上, ...
- Linux命令:tail命令详解
概述:tail命令显示文件末尾区块,也可以查看线上日志 1.格式 tail [参数][文件] 2.参数 -f 循环读取 -q 不显示处理信息 -v 显示详细的处理信息 -c<数目> 显示的 ...
- 基于ProGuard-Maven-Plugin的自定义代码混淆插件
介绍 大家可能都会碰到一些代码比较敏感的项目场景,这个时候代码被反编译看到就不好了,这个时候就需要代码混淆插件来对代码进行混淆了. 基于Maven的项目一般会去考虑使用proguard-maven-p ...
- Cocos Studio1.5.0.1开发学习笔记(一)
听说Cocos Studio很久了,主要是因为骨骼动画.目前看来Cocos2d-x播放动画的方式只有2种: 第一种:是播放序列帧动画,即将动画的每一帧都加载进缓存里,需要播放时再使用Animation ...
- confluence5.8.10的使用
之前在windows上安装了confluence5.8.10,结果有一天知什么缘故,数据库数据损坏,知识库彻底打不开了,所有的文档都付之东流,真的不是一般心痛.因此考虑将其装到linux机器上,因为t ...
- shell用if
--------- shell用if出错了,Why? shell if 实例: site=github.com/fankcoder if [ $site == github.com/fankcoder ...
- ng-class css样式
<style> .error{background-color: red;} .warning{background-color: yellow;} </style> < ...
- Apache:To Config The Vhost of Django Project
It is not a good idea to use dev server in Production Environment. Apache or Nginx are good choice.B ...
- 快速访问WCF服务--ServiceModel 元数据实用工具 (Svcutil.exe)
基本定义 ServiceModel 元数据实用工具用于依据元数据文档生成服务模型代码,以及依据服务模型代码生成元数据文档. SvcUtil.exe ServiceModel 元数据实用工具可在 Win ...
- 关于SQL server的一些知识点
关于怎么打开xp_cmdshell的方法: exec sp_configure 'show advanced option',1reconfiguregoexec sp_configure 'xp_c ...