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 现在你已经有一 ...
随机推荐
- 【DFS求树的最大二分匹配+输入外挂】HDU 6178 Monkeys
http://acm.hdu.edu.cn/showproblem.php?pid=6178 [题意] 给定一棵有n个结点的树,现在有k个猴子分布在k个结点上,我们可以删去树上的一些边,使得k个猴子每 ...
- 【DFS序+树状数组】BNUOJ 52733 Random Numbers
http://acm.bnu.edu.cn/v3/problem_show.php?pid=52733 [题意] 给定一棵树,这棵树每个点都有一个点权,标号从0开始,0是根结点 修改操作: SEED ...
- response.setHeader参数、用法的介绍
response.setHeader 是用来设置返回页面的头 meta 信息, 使用时 response.setHeader( name, contect ); meta是用来在HTML文档中模拟HT ...
- 使用反射获取类中的属性(可用于动态返回PO类的列,当做表格的表头)
//利用反射取类中的属性字段 try { Class clazz = Class.forName("houji.bean.model.TaskModel"); Field[] fi ...
- Bichrome Tree
Bichrome Tree 时间限制: 1 Sec 内存限制: 128 MB 题目描述 We have a tree with N vertices. Vertex 1 is the root of ...
- Scrapy学习-9-FromRequest
用FromRequest模拟登陆知乎网站 实例 默认登陆成功以后的请求都会带上cookie # -*- coding: utf-8 -*- import re import json import d ...
- c++ 高效并发编程
高效并发编程 并发编程的基本模型包括,通过消息机制来管理运行顺序的message passing, 通过互斥保护共享的shared memory. 线程同步的基本原则 最低限度共享变量,考虑使用imm ...
- CentOS yum update 与 yum upgrade 区别
yum -y update 升级所有包同时也升级软件和系统内核 yum -y upgrade 只升级所有包,不升级软件和系统内核 官方文档:https://access.redhat.com/docu ...
- Set 技巧之一
我们知道set中 用set<int,int>S; S.lower_bound(x): 查找Set中 第一个>=x的数,返回结果是指针. S.upper_bound(x):查找Set中 ...
- ubuntu16.04安装mysql5.7.15
1.在官网下载mysql安装包 直接选择第一个下载好了就行 2.进入你的下载文件夹下面 键入命令: tar -xvf mysql-server_5.7.13-1ubuntu16.04_i386.deb ...