CODEFORCES 25E Test
来源:互联网 发布:推荐好看的小说知乎 编辑:程序博客网 时间:2024/06/03 22:45
题意
三个字符串,找一个字符串(它的子串含有以上三个字符串)使它的长度最短,输出此字符串的长度。
题解
先枚举字符串排列,直接KMP两两匹配,拼接即可。。。答案取最小值。。
常数巨大的丑陋代码
# include <stdio.h># include <stdlib.h># include <iostream># include <string.h># include <algorithm>using namespace std;# define IL inline# define RG register# define UN unsigned# define ll long long# define rep(i, a, b) for(RG int i = a; i <= b; i++)# define per(i, a, b) for(RG int i = b; i >= a; i--)# define mem(a, b) memset(a, b, sizeof(a))# define max(a, b) ((a) > (b)) ? (a) : (b)# define min(a, b) ((a) < (b)) ? (a) : (b)# define Swap(a, b) a ^= b, b ^= a, a ^= b;const int MAXN = 100001;int len, nt[MAXN], cnt = 2147483647;char ans[MAXN*3];IL void KMP(RG char s[]){ RG int l = strlen(s), j = 0; mem(nt, 0); rep(i, 1, l - 1){ while(j && s[i] != s[j]) j = nt[j-1]; if(s[i] == s[j]) j++; nt[i] = j; } j = 0; rep(i, 0, len-1){ while(j && ans[i] != s[j]) j = nt[j-1]; if(ans[i] == s[j]) j++; if(j == l) return; //少了这个会WA!!! } while(j < l) ans[len++] = s[j++];}IL void Work(RG char s1[], char s2[], char s3[]){ len = strlen(s3); rep(i, 0, len-1) ans[i] = s3[i]; KMP(s1); KMP(s2); cnt = min(cnt, len);}int main(){ char ss1[MAXN], ss2[MAXN], ss3[MAXN]; scanf(" %s %s %s", ss1, ss2, ss3); Work(ss1, ss2, ss3); Work(ss1, ss3, ss2); Work(ss2, ss1, ss3); Work(ss2, ss3, ss1); Work(ss3, ss1, ss2); Work(ss3, ss2, ss1); printf("%d\n", cnt); return 0;}
阅读全文
0 0
- CodeForces 25E Test
- CODEFORCES 25E Test
- CODEFORCES 25E Test
- CodeForces 25E Test KMP
- CodeForces 25E Test KMP
- CodeForces - 25E Test (KMP应用)
- codeforces #25E
- Codeforces 25A IQ test
- 【CodeForces】[25A]IQ test
- CF-25E - Test(KMP)
- CodeForces 825E Educational #25 E:拓扑排序+优先队列
- CodeForces 25A IQ test 唯一奇偶
- Codeforces 25E 字符串hash模板题
- Educational Codeforces Round 25 E. Minimal Labels
- Educational Codeforces Round 25 E. Minimal Labels
- cf Educational Codeforces Round 25 E
- codeforces 163E e-Government
- 【Codeforces 163E】E-Government
- 使用 Thrift 进行文件传输
- 机房重构验收一重构系统
- 【Eternallyc】大数素数判断
- K
- 自定义View之 继承View
- CODEFORCES 25E Test
- BZOJ 1025-游戏(数论+DP)
- Large Division(大数取余)
- springboot事务管理
- oracle数据库的增删查改
- 【随心笔录】Android多进程实现,一个APP多个进程
- Java中的单例、策略、适配器模式
- HDU 1016 Prime Ring Problem
- Python——学生成绩管理系统