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 ...
随机推荐
- 如何管理你的 Javascript 代码
今天不聊技术的问题,咱们来聊聊在前端开发中如何管理好自己的 Javascript 代码.首先,咱们先来说说一般都有哪些管理方式?我相信 seajs . requirejs 对于前端开发者而言都不陌 ...
- 使用charles proxy for Mac来抓取手机App的网络包
之前做Web项目的时候,经常会使用Fiddler(Windows下).Charles Proxy(Mac下)来抓包,调试一些东西:现在搞Android App开发,有时候也需要分析手机App的网络请求 ...
- Java之webService知识
Java之webService知识 1 webservice基础知识 1.1 webService请求的本质 一次webService本质请求,如下所示: 1.2 wsdl文档解析 wsdl文档元素结 ...
- Java----多线程知识点归纳(概念)
一.线程与进程的区别: 多个进程的内部数据和状态都是完全独立的,而多线程是共享一块内存空间和一组系统资源,有可能互相影响. ?线程本身的数据通常只有寄存器数据,以及一个 程序执行时使用的堆栈,所以线程 ...
- java——输入流FileInputStream
写一个简单的程序,实现从电脑中的一个盘里的文件中往程序中输入内容. package com.liaojianya.chapter5; import java.io.FileInputStream; i ...
- SGU 113.Nearly prime numbers
水一个代码: #include <iostream> using namespace std; int n, a; bool ok; bool prime (int x) { ; i * ...
- dedecms 修改标题长度可以修改数据库
数据表为dede__archives 字段为title 首先要在 a.系统->系统基本参数->其它选项->文章标题长度 b.系统->SQL命令行工具 alter table # ...
- Win8.1 64bit安装Genymotion模拟器
其实安装并不复杂,只要环境正常,此事并不难.但估计最坏的情况都被我撞上了,才折腾了差不多一天的 那我有哪些环境不正常呢? 破解了系统主题 Device Install Service服务未启动 下面来 ...
- 用Web Picasa API搭建站内相册
在flickr时代,为了专门把站内嵌入相册,还专门写了一篇文章把Flickr相册搬回家.flickr被墙之后,我就把个人相册转到了Web Picasa上.用Picasa Web就简单多了,官方提供了S ...
- 用Apache实现一个ip虚拟多个web站点
如何用Apache实现一个ip虚拟多个web站点? 首先添加虚拟的服务器名 <virtualhost www.xxx.com:80="">DocumentRoot d: ...