(KMP 暴力)Corporate Identity -- hdu -- 2328
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): 698 Accepted Submission(s): 281
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.
IDENTITY LOST
代码:
- #include<iostream>
- #include<stdio.h>
- #include<string.h>
- using namespace std;
- #define M 40005
- #define N 210
- char s[M][N];
- int Next[N];
- void FindNext(char b[])
- {
- int i=, j=-, blen=strlen(b);
- Next[] = -;
- while(i<blen)
- {
- if(j==- || b[i]==b[j])
- Next[++i] = ++j;
- else
- j = Next[j];
- }
- }
- int KMP(char a[], char b[])
- {
- int i=, j=;
- int alen=strlen(a), blen=strlen(b);
- FindNext(b);
- while(i<alen)
- {
- while(j==- || (a[i]==b[j] && i<alen && j<blen))
- i++, j++;
- if(j==blen)
- return ;
- j = Next[j];
- }
- return ;
- }
- int main()
- {
- int n;
- while(scanf("%d", &n), n)
- {
- int i, j, k, MinLen=, len;
- char ss[N];
- memset(s, , sizeof(s));
- for(i=; i<n; i++)
- {
- scanf("%s", s[i]);
- len = strlen(s[i]);
- if(len<MinLen)
- {
- MinLen = len;
- memset(ss, , sizeof(ss));
- strcpy(ss, s[i]);
- }
- }
- char b[N]="{";
- int index=;
- for(i=MinLen; i>; i--)
- {
- for(j=; j<=MinLen-i; j++)
- {
- char a[N];
- memset(a, , sizeof(a));
- strncpy(a, ss+j, i);
- for(k=; k<n; k++)
- {
- if(KMP(s[k], a)==)
- break;
- }
- if(k==n && strcmp(a, b)<)
- {
- index = i;
- strcpy(b, a);
- }
- if(index && j==MinLen-i)
- i=-, j=;
- }
- }
- if(index)
- printf("%s\n", b);
- else
- printf("IDENTITY LOST\n");
- }
- return ;
- }
(KMP 暴力)Corporate Identity -- hdu -- 2328的更多相关文章
- Corporate Identity - HDU 2328(多串求共同子串)
题目大意:给你N(2-4000)个字符串,求出来他们的共同子串 分析:因为上次就说了再出现这种题就不用那种暴力的做法了,于是看了一些别的知识,也就是后缀树,把一个字符串的所有的后缀全部都加入字典树 ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- hdu 2328 Corporate Identity(kmp)
Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...
- hdu2328 Corporate Identity【string库使用】【暴力】【KMP】
Corporate Identity Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- POJ 题目3450 Corporate Identity(KMP 暴力)
Corporate Identity Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5493 Accepted: 201 ...
- POJ-3450 Corporate Identity (KMP+后缀数组)
Description Beside other services, ACM helps companies to clearly state their “corporate identity”, ...
- hdu2328 Corporate Identity 扩展KMP
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- hdu2328 Corporate Identity
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题目: Corporate Identity Time Limit: 9000/3000 MS (J ...
- N - Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
随机推荐
- MySQL的事务处理及隔离级别
事务是DBMS得执行单位.它由有限得数据库操作序列组成得.但不是任意得数据库操作序列都能成为事务.一般来说,事务是必须满足4个条件(ACID) 原子性(Autmic):事务在执行性,要 ...
- Mysql binlog二进制日志
Mysql binlog日志有三种格式,分别为Statement,MiXED,以及ROW! 1.Statement:每一条会修改数据的实际原sql语句都会被记录在binlog中. 优点:不需要记录每一 ...
- orientdb 学习
简介 OrientDB 是一款 NoSQL 数据库.是一种文档-图数据库.即:既具有文档数据库的特性,又具有图数据库的功能. 端口 2424 OrientDB 监听 二进制 访问的的端口 (即:通过 ...
- 在hadoop运行tensor flow
http://www.infoq.com/cn/articles/deeplearning-tensorflow-casestudy http://www.tuicool.com/articles/a ...
- oracle 文件系统
oracle数据文件信息 select * from v$datafile;--查看数据文件信息select * from v$controlfile;--查看控制文件信息 一.控制文件(Contro ...
- QT隐式数据共享
QT中许多C++类使用了隐式数据共享,最小化资源拷贝.当作为参数传递时,实际只传递了指针,这是底层完成的,程序员无需担心,即使是在多线程中,从Qt4开始: 记住,尽量使用const迭代器,vector ...
- strcpy函数;memcpy函数;memmove函数
strcpy函数实现: char* strcpy(char* des,const char* source) { char* r=des; assert((des != NULL) && ...
- JavaScript 中的 NaN 和 isNaN
1.NaN NaN 即 Not a Number , 不是一个数字.那么 NaN 到底是什么呢? 在 JavaScript 中,整数和浮点数都统称为 Number 类型 .除此之外,Number 类型 ...
- 面向对象设计模式纵横谈:Builder 生成器模式(笔记记录)
Builder模式的缘起 假设创建游戏中的一个房屋House设施,该房屋的构建由几个部分组成,且各个部分要富于变化. 如果使用最直观的设计方法,每一个房屋部分的变化,都将导致房屋构建的重新修正…… 动 ...
- super限定,子类中系统查找变量的顺序:
示例代码如下: import static java.lang.System.*; //-父类: class BaseClass{ public int a=7; } //-子类: public cl ...