CODEFORCES 25E Test
题意
三个字符串,找一个字符串(它的子串含有以上三个字符串)使它的长度最短,输出此字符串的长度。
题解
先枚举字符串排列,直接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;
}
CODEFORCES 25E Test的更多相关文章
- Codeforces 25E Test 【Hash】
Codeforces 25E Test E. Test Sometimes it is hard to prepare tests for programming problems. Now Bob ...
- CodeForces 25E Test KMP
Description Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tes ...
- [codeforces] 25E Test || hash
原题 给你三个字符串,找一个字符串(它的子串含有以上三个字符串),输出此字符串的长度. 先暴力判断是否有包含,消减需要匹配的串的数量.因为只有三个字符串,所以暴力枚举三个串的位置关系,对三个串跑好哈希 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- Hive metastore源码阅读(二)
最近随着项目的深入,发现hive meta有些弊端,就是你会发现它的元数据操作与操作物理集群的代码耦合在一起,非常不利于扩展.比如:在create_table的时候同时进行路径校验及创建,如下代码: ...
- PHPUnit-附录 A. 断言 (assert)
[http://www.phpunit.cn/manual/5.7/zh_cn/appendixes.assertions.html] 本附录列举可用的各种断言方法. assertArrayHasKe ...
- 如何通过以太坊智能合约来进行众筹(ICO)
前面我们有两遍文章写了如何发行代币,今天我们讲一下如何使用代币来公开募资,即编写一个募资合约. 写在前面 本文所讲的代币是使用以太坊智能合约创建,阅读本文前,你应该对以太坊.智能合约有所了解,如果你还 ...
- ch11 持有对象
Java集合的基本类型:List.Set.Queue.Map 使用容器时若未指定泛型参数ArrayList apples=new ArrayList();,则容器中所有元素都为Object类型,使用时 ...
- SQLSERVER中分割字符串成多列
今天修改到之前的大佬的代码,居然把多个Id存在一个列里面,还是用的逗号分割...特么查询的时候怎么办??? 网上搜索了半天,终于找到了SqlServer里面有一个PARSENAME函数,可以按.(点) ...
- hihoCoder 1036 Trie图 AC自动机
题意:给定n个模式串和一个文本串,判断文本中是否存在模式串. 思路:套模板即可. AC代码 #include <cstdio> #include <cmath> #includ ...
- CodeForces-749B
给定3个坐标,求可能构成平行四边形的第四个点,枚举两个点,根据这两个点的横纵坐标差,来得到第四个点的坐标,注意生成的坐标需要判重. AC代码: #include<cstdio> #incl ...
- 算法训练 K好数 数位DP+同余定理
思路:d(i,j)表示以i开头,长度为j的K好数的个数,转移方程就是 for(int u = 0; u < k; ++u) { int x = abs(i - u); if(x == 1) co ...
- php基本函数的学习(2)
chgrp chgrp — 改变文件所属的组 说明: bool chgrp ( string $filename , mixed $group ) 尝试将文件 filename 所属的组改成 grou ...
- Docker系列三:Docker容器管理
Docker容器管理 1. 单一容器管理 1) 容器的启动 $ docker run --name gitlab-redis -d --volume /srv/docker/gitlab/redis: ...