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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- CSS单行、多行文本溢出显示省略号
如果实现单行文本的溢出显示省略号小伙伴们应该都知道用text-overflow:ellipsis属性来,当然还需要加宽度width属来兼容部分浏览. 实现方法: overflow: hidden; t ...
- IE8兼容问题总结---trim()方法
1.IE8不支持,jquery的trim()去空格的方法 错误表现 : 会报错,对象不支持此属性或方法; 解决办法 : 使用正则匹配空格 例如 : /^\s+|\s+$/greplace(/^\s+| ...
- c++ 回调函数使用
普通回调 #include<stdio.h> void printWelcome(int len) { printf("welcome -- %d\n", len); ...
- flask中jinjia2模板引擎使用详解1
在之前的文章中我们介绍过flask调用jinja2模板的基本使用,这次我们来说一下jinjia2模板的使用 Jinja2 在其是一个 Python 2.4 库之前,被设计 为是灵活.快速和安全的. 模 ...
- (转载)SVM-基础(二)
支持向量机: Support Vector by pluskid, on 2010-09-10, in Machine Learning 52 comments 本文是"支持向量机 ...
- LRUCache原理分析
一.注释 LRUCache的原理,基本都在注释里面描述清楚了. /** * A cache that holds strong references to a limited number of va ...
- xpadder教程:自定义设置游戏手柄的图片
关于xpadder设置按键的教程,网上已经很多,我就不凑这个热闹了.这里介绍的是如何自定义设置手柄的图片,就是按钮的背景图,如下图所示: 步骤: 1)准备一张背景图 注意:格式必须是24位色的BMP位 ...
- C语言老司机学Python (六)- 多线程
前面的1-5都是比较基础的东西,能做的事情也有限. 从本节起,随着更多进阶技术的掌握,渐渐就可以用Python开始浪了. Python3使用threading模块来实现线程操作. 根据在其他语言处学来 ...
- 关于longPressGesture做一个长按连加的效果(原创)
关于longPressGesture做一个长按连加的效果 解释一下什么意思呢?就是一个button长按之后其数字的一直累加.朋友们可能看起来很简单,无非就是加一个长按手势(longPressGestu ...
- ffmpeg在am335x上的移植
交叉编译工具:arm-linux-gcc 一.先下载一下文件 1. yasm-1.2.0.tar.gz 2. x264-snapshot-20140424-2245.tar.bz2 3. xvidco ...