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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- [Python Study Notes]匿名函数
Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...
- SmokePing 部署实践
1 通过 yum 安装依赖的库以及环境 yum install rrdtool wqy* fping curl bind-utils httpd httpd-devel \ perl perl-FCG ...
- 安装 LightGBM 包的过程
conda install cmake conda install gcc git clone --recursive https://github.com/Microsoft/LightGBM ; ...
- 机器学习之支持向量机(四):支持向量机的Python语言实现
注:关于支持向量机系列文章是借鉴大神的神作,加以自己的理解写成的:若对原作者有损请告知,我会及时处理.转载请标明来源. 序: 我在支持向量机系列中主要讲支持向量机的公式推导,第一部分讲到推出拉格朗日对 ...
- CodeForces-749B
给定3个坐标,求可能构成平行四边形的第四个点,枚举两个点,根据这两个点的横纵坐标差,来得到第四个点的坐标,注意生成的坐标需要判重. AC代码: #include<cstdio> #incl ...
- hdu4825 01字典树+贪心
从高位向低位构造字典树,因为高位得到的数更大. AC代码: #include<cstdio> using namespace std; typedef long long LL; cons ...
- Hadoop1.x原理
将这种单机的工作进行分拆,变成协同工作的集群,这就是分布式计算框架设计.使得计算机硬件类似于应用程序中资源池的资源,使用者无需关心资源的分配情况,从而最大化了硬件资源的使用价值.分布式计算也是如此,具 ...
- S3 Browser 配置指南
S3 Browser 相对于s3cmd是一个很方便的操作S3的图形化界面工具. 以下是配置步骤: 下载网址:http://s3browser.com/ keygen破解版: http://appdol ...
- linux Cacti监控服务器搭建
搭建Cacti监控服务器 部署安装环境(lamp) [root@zhuji1 ~]# yum -y install httpd [root@zhuji1 ~]# yum -y install php ...
- 面向对象的线程池Threadpool的封装
线程池是一种多线程处理形式,预先创建好一定数量的线程,将其保存于一个容器中(如vector), 处理过程中将任务添加到队列,然后从容器中取出线程后自动启动这些任务,具体实现如下. 以下是UML图,展示 ...