博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Beta Round #25 (Div. 2 Only)E. Test
阅读量:5279 次
发布时间:2019-06-14

本文共 2361 字,大约阅读时间需要 7 分钟。

E. Test
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring s1, the second enters an infinite loop if the input data contains the substring s2, and the third requires too much memory if the input data contains the substring s3. Bob wants these solutions to fail single test. What is the minimal length of test, which couldn't be passed by all three Bob's solutions?

Input

There are exactly 3 lines in the input data. The i-th line contains string si. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105.

Output

Output one number — what is minimal length of the string, containing s1, s2 and s3 as substrings.

Sample test(s)
input
ab bc cd
output
4
input
abacaba abaaba x
output
11

 KMP

给你3个子串,求最短的原串。

例如

abc

ab

c

最短原串就是abc

/* ***********************************************Author        :pk29Created Time  :2015/8/23 18:41:02File Name     :4.cpp************************************************ */#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ull unsigned long long#define ll long long#define mod 90001#define INF 0x3f3f3f3f#define maxn 100000+10#define cle(a) memset(a,0,sizeof(a))const ull inf = 1LL << 61;const double eps=1e-5;using namespace std;int f[maxn];void getFail(string p,int *f){ int m=p.size(); f[0]=0; f[1]=0; for(int i=1;i
>s[0]>>s[1]>>s[2]){ if(s[0]>s[1])swap(s[0],s[1]); if(s[1]>s[2])swap(s[1],s[2]); if(s[0]>s[1])swap(s[0],s[1]); //next_permutation()使用前得先排序 int ans=INF; int num=1; do{ string t=""; t+=s[0]; int a=find(t,s[1],f); t+=s[1].substr(s[1].size()-a,a); int b=find(t,s[2],f); int x=t.size()+b; ans=min(ans,x); }while(next_permutation(s,s+3)); cout<
<

 

转载于:https://www.cnblogs.com/pk28/p/4755757.html

你可能感兴趣的文章
解决CentOS6.x或RedHat Linux 6.x版本不能通过System eth0以固定IP访问外网的问题
查看>>
(转)Expression Tree不完全入门
查看>>
Struts2的工作原理
查看>>
配置EditPlus使其可以编译运行java程序
查看>>
我眼中的Android IDE
查看>>
C++默认参数值函数
查看>>
java中的占位符\t\n\r\f
查看>>
7.14
查看>>
SDN2017 第一次作业
查看>>
MySQL通过frm 和 ibd 恢复数据过程
查看>>
AngularJs 学习笔记(2)
查看>>
关于元素优先级
查看>>
oo第一单元作业总结
查看>>
SRS源码——Listener
查看>>
web.xml 4.0 头
查看>>
Java面向对象抽象类案例分析
查看>>
ApacheCN 活动汇总 2019.2
查看>>
jquery动态表格,动态添加表格行
查看>>
将中文汉字转换成拼音(全拼)
查看>>
网络流 - 上下界网络流
查看>>