Codeforces Beta Round #25 (Div. 2 Only)E. Test
2 seconds
256 megabytes
standard input
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?
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 one number — what is minimal length of the string, containing s1, s2 and s3 as substrings.
ab
bc
cd
4
abacaba
abaaba
x
11
KMP
给你3个子串,求最短的原串。
例如
abc
ab
c
最短原串就是abc
/* ***********************************************
Author :pk29
Created Time :2015/8/23 18:41:02
File Name :4.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#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 << ;
const double eps=1e-;
using namespace std; int f[maxn];
void getFail(string p,int *f){
int m=p.size();
f[]=;
f[]=;
for(int i=;i<m;i++){
int j=f[i];
while(j&&p[i]!=p[j])j=f[j];
f[i+]=p[i]==p[j]?j+:;
}
}
int find(string t,string p,int *f){
int n=t.size(),m=p.size();
getFail(p,f);
int j=;
for(int i=;i<n;i++){
while(j&&p[j]!=t[i])j=f[j];
if(p[j]==t[i])j++;
if(j==m)return ;//一开始没考率到主串包含子串,wa成狗
}
return m-j;
} string s[];
int arr[]={,,};
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
while(cin>>s[]>>s[]>>s[]){
if(s[]>s[])swap(s[],s[]);
if(s[]>s[])swap(s[],s[]);
if(s[]>s[])swap(s[],s[]);
//next_permutation()使用前得先排序
int ans=INF;
int num=;
do{
string t="";
t+=s[];
int a=find(t,s[],f);
t+=s[].substr(s[].size()-a,a);
int b=find(t,s[],f);
int x=t.size()+b;
ans=min(ans,x);
}while(next_permutation(s,s+));
cout<<ans<<endl;
}
return ;
}
Codeforces Beta Round #25 (Div. 2 Only)E. Test的更多相关文章
- Codeforces Beta Round #25 (Div. 2 Only)
Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A #include<bits/stdc++.h ...
- codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)
题目链接:http://www.codeforces.com/problemset/problem/25/A题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数.C++代码: #include ...
- Codeforces Beta Round #25 (Div. 2)--A. IQ test
IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Beta Round #25 (Div. 2 Only) A. IQ test【双标记/求给定数中唯一的奇数或偶数】
A. IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland
D. Roads not only in Berland time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Beta Round #25 (Div. 2 Only) C. Roads in Berland
C. Roads in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #49 (Div. 2)
Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
随机推荐
- 洛谷P3758 - [TJOI2017]可乐
Portal Description 给出一张\(n(n\leq30)\)个点\(m(m\leq100)\)条边的无向图.初始时有一个可乐机器人在点\(1\),这个机器人每秒会做出以下三种行为之一:原 ...
- MyBatipse插件
MyBatipse:Eclipse 下的 Mybatis插件 MyBatipse是Eclipse的一个插件,提供了内容提示和Mybatis的配置文件验证功能: 特点 XMLEditor 的增强 代码自 ...
- 费用流(bzoj 3130)
Description Alice和Bob在图论课程上学习了最大流和最小费用最大流的相关知识. 最大流问题:给定一张有向图表示运输网络,一个源点S和一个汇点T,每条边都有最大流量.一个合法的网络 ...
- linux与windows查看占用端口的进程ID并杀死进程
有时候tomcat出现端口被占用,需要查出进程ID并杀死进程. 1.查找占用端口的进程ID(windows与linux一样 8005也可以加上引号 grep可以用findstr替换) 6904就 ...
- 标准C程序设计七---10
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- C++ 中new
operator new在C++中的各种写法 (2011-09-21 14:59:33) 标签: 杂谈 乍一看,在C++中动态分配内存很简单:new是分配,delete是释放,就这么简单.然而,这 ...
- 更改App名称
To change the installed application name, in Xcode: 1. Select your Target on the left side under Gro ...
- Elixir与编辑器安装
安装 Elixir 每个操作系统的安装说明可以在 elixir-lang.org 网站上 Installing Elixir 部分找到. 安装后你可以很轻松地确认所安装的版本. ~$:elixir - ...
- commons.apache
1.ToStringBuilder //对象及其属性一行显示 System.out.println(ToStringBuilder.reflectionToString(u)); System.out ...
- 感受lambda之美,推荐收藏,需要时查阅
一.引言二.java重要的函数式接口1.什么是函数式接口1.1 java8自带的常用函数式接口.1.2 惰性求值与及早求值2.常用的流2.1 collect(Collectors.toList())2 ...