题意:求最长的a的前缀同时满足是b的后缀,把a,b连在一起,kmp跑一下,迭代next直到长度小于等于a,b长度的最小值为止,即为答案。

 #pragma comment(linker, "/STACK:10240000,10240000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <stdexcept>
#include <utility> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define mem_1(a) memset(a, -1, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep_up0(a, b) for (int a = 0; a < (b); a++)
#define rep_up1(a, b) for (int a = 1; a <= (b); a++)
#define rep_down0(a, b) for (int a = b - 1; a >= 0; a--)
#define rep_down1(a, b) for (int a = b; a > 0; a--)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pchr(a) putchar(a)
#define pstr(a) printf("%s", a)
#define sstr(a) scanf("%s", a)
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d%d", &a, &b)
#define sint3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define pint(a) printf("%d\n", a)
#define test_print1(a) cout << "var1 = " << a << endl
#define test_print2(a, b) cout << "var1 = " << a << ", var2 = " << b << endl
#define test_print3(a, b, c) cout << "var1 = " << a << ", var2 = " << b << ", var3 = " << c << endl typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii; const int dx[] = {, , -, , , , -, -};
const int dy[] = {-, , , , , -, , - };
const int maxn = 2e5 + ;
const int md = ;
const int inf = 1e9 + ;
const LL inf_L = 1e18 + ;
const double pi = acos(-1.0);
const double eps = 1e-; template<class T>T gcd(T a, T b){return b==?a:gcd(b,a%b);}
template<class T>bool max_update(T &a,const T &b){if(b>a){a = b; return true;}return false;}
template<class T>bool min_update(T &a,const T &b){if(b<a){a = b; return true;}return false;}
template<class T>T condition(bool f, T a, T b){return f?a:b;}
template<class T>void copy_arr(T a[], T b[], int n){rep_up0(i,n)a[i]=b[i];}
int make_id(int x, int y, int n) { return x * n + y; } struct KMP {
int next[];
void GetNext(char s[]) {
mem0(next);
next[] = next[] = ;
for(int i = ; s[i]; i++) {
int j = next[i];
while(j && s[i] != s[j]) j = next[j];
next[i + ] = s[j] == s[i]? j + : ;
}
}
}; KMP kmp;
char s[maxn], s2[maxn]; int main() {
//freopen("in.txt", "r", stdin);
while (~scanf("%s%s", s, s2)) {
int len = strlen(s), len2 = strlen(s2);
rep_up0(i, len2) s[len + i] = s2[i];
s[len + len2] = ;
kmp.GetNext(s);
int pos = len + len2, minlen = min(len, len2);
while (pos && pos > minlen) pos = kmp.next[pos];
rep_up0(i, pos) pchr(s[i]);
if (pos) pchr(' ');
printf("%d\n", pos);
}
return ;
}

最新文章

  1. 图解DevExpress RichEditControl富文本的使用,附源码及官方API
  2. xamarin UWP中MessageDialog与ContentDialog的区别
  3. test2
  4. 清除Cookie、获取指定Cookie的值、添加一个Cookie(24小时过期)、添加一个Cookie
  5. contains
  6. sqlserver 批量删除存储过程和批量修改存储过程的语句
  7. LA 3882
  8. 访问项目时,不能自动加载index.php文件
  9. [AOP系列]Autofac+Castle实现AOP日志
  10. JavaScript在应用中的技巧(一)
  11. NameError: name &#39;messagebox&#39; is not defined 错误处理
  12. Python脱产8期 Day13 2019/4/28
  13. 炸弹人游戏开发系列(7):加入敌人,使用A*算法寻路
  14. Github 入门(“趣考网络”学习第一步)
  15. stm32定时器输出移相PWM(非主从模式)
  16. mysql表关联
  17. 微服务架构基础之Service Mesh
  18. hdu 1907 (尼姆博弈)
  19. Linux - PS1
  20. 使用wxpy来实现自动发送消息统计微信好友信息的功能

热门文章

  1. 详解 普通数组 —— Arrays类 与 浅克隆
  2. testNG 断言
  3. ubuntu搭建vulhub漏洞环境
  4. python爬虫(1)requests库
  5. Selenium常见报错问题(1)- 先来认识下selenium常见异常类
  6. 第九次-DFA最小化,语法分析初步
  7. Inno Script - How to make “I Accept the Agreement” radio button on EULA page selected by Default
  8. MySQL系列(二)
  9. Python与Excel交互——Xlwings实战
  10. 利用python画出SJF调度图