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 ...
随机推荐
- xceed wpf datagrid
<!--*********************************************************************************** Extended ...
- Relative与Absolute组合使用
小伙伴们学习了绝对定位的方法:使用position:absolute可以实现被设置元素相对于浏览器(body)设置定位以后, 大家有没有想过可不可以相对于其它元素进行定位呢?答案是肯定的,当然可以.使 ...
- Qt经典出错信息之”Basic XLib functionality test failed!”
解决方法: 此完整出错信息是在./configure阶段Basic XLib functionality test failed!You might need to modify the includ ...
- jQuery慢慢啃之CSS(六)
1.css(name|pro|[,val|fn])//访问匹配元素的样式属性 $("p").css("color");//获取 $("p") ...
- CentOS7开机启动管理systemd简介及使用
systemd提供更优秀的框架以表示系统服务间的依赖关系实现系统初始化时服务的并行启动,同时达到降低Shell的系统开销的效果systemd的目标是:尽可能启动更少进程:尽可能将更多进程并行启动.sy ...
- 网页布局只mian部分左右固定,中间部分自适应
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 我和CPP的第二次约会
1.变量之间的运算形式依赖于变量的数据类型,如i = i + j;当 i 和 j 是整型或者浮点型,则代表两个数的相加,如果是第一章所说的Sales_item类型,那么就是这两个变量的成分相加(如果书 ...
- HashMap在Android和Java中的不同实现
起因 今天在项目中遇到一个很"奇葩"的问题.情况大致是这样的:Android终端和服务器(Spring),完全相同的字符串键值对放入HashMap中竟然顺序不一样,这直接导致了服务 ...
- libcurl的封装,支持同步异步请求,支持多线程下载,支持https
最近在做一个项目,需要用到http get post等 需求分析需要做到同步和异步,异步请求的返回以可选的回调通知的方式进行. 本人以Linux为例,一步一步的来实现. 配置并且编译libcurl我以 ...
- Comparing randomized search and grid search for hyperparameter estimation
Comparing randomized search and grid search for hyperparameter estimation Compare randomized search ...