hdu3294 manacher算法
来源:互联网 发布:php redis 扩展 编辑:程序博客网 时间:2024/04/28 12:15
/**********************jibancanyang************************** *Author :jibancanyang *Created Time : 五 4/29 09:56:27 2016 *File Name : hdu3294.cpp *Problem:简单manacher+替换 *Get:***********************1599664856@qq.com**********************/#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <stack>using namespace std;typedef pair<int, int> pii;typedef long long ll;typedef unsigned long long ull;vector<int> vi;#define pr(x) cout << #x << ": " << x << " " #define pl(x) cout << #x << ": " << x << endl;#define xx first#define yy second#define sa(n) scanf("%d", &(n))#define sal(n) scanf("%lld", &(n))#define sai(n) scanf("%I64d", &(n))#define rep(i, a, n) for (int i = a; i < n; i++)#define vep(c) for(decltype((c).begin() ) it = (c).begin(); it != (c).end(); it++) const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 2e5 + 12;char key, st[maxn], aim[maxn * 2];int slen, ti, P[maxn * 2];void pre(){ slen = (int)strlen(st); ti = 0; if (slen == 0) {aim[0] = '^', aim[1] = '$'; return;} aim[ti++] = '^'; for (int i = 0; i < (int)slen; i++) aim[ti++] = '#', aim[ti++] = st[i]; aim[ti++] = '#', aim[ti++] = '$';}pii manacher(void){ pre(); int C = 0, R = 0; for (int i = 1; i < ti - 1; i++) { int i_mirror = 2 * C - i; P[i] = (R > i) ? min(R - i, P[i_mirror]) : 0; while (aim[i + 1 + P[i]] == aim[i - 1 - P[i]]) P[i]++; if (i + P[i] > R) C = i, R = i + P[i]; } int maxlen = 0, cen = 0; for (int i = 1; i < ti - 1; i++) if (P[i] > maxlen) maxlen = P[i], cen = i; return pii((cen - 1 - maxlen) / 2, (cen - 1 - maxlen) / 2 + maxlen - 1);}int main(void){#ifdef LOCAL //freopen("/Users/zhaoyang/in.txt", "r", stdin); //freopen("/Users/zhaoyang/out.txt", "w", stdout);#endif ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); while (~scanf("%c%s", &key, st)) { getchar(); pii point = manacher(); if (point.xx == point.yy) puts("No solution!"); else { printf("%d %d\n", point.xx, point.yy); rep (i, point.xx, point.yy + 1) { printf("%c", 'a' + (st[i] - 'a' - (key - 'a') + 26) % 26); } puts(""); } } return 0;}
0 0
- hdu3294之manacher算法
- hdu3294(Manacher算法)
- 【HDU3294,URAL1294】manacher算法
- 【manacher算法】HDU3294 URAL1297
- hdu3294 manacher算法
- hdu3294 Girls' research 【manacher算法】
- HDU3294 manacher
- Girls' research(hdu3294+Manacher算法)
- hdu3068&&hdu3294,回文串,Manacher算法
- HDU3294 Girls' research(Manacher算法)
- hdu3068+hdu3294 最长回文字符串的manacher算法
- hdu3294 Girls' research (manacher算法,最大回文子串)
- hdu3294(manacher)
- hdu3294 Girls' research(manacher)
- hdu3294 Girls' research(manacher)
- HDU3294——Girls' research(manacher算法,马拉车算法)
- Manacher算法
- Manacher算法
- android里面的USB功能----Host模式
- hdu 1035 Robot Motion
- Quartz2D图片裁剪圆的做法
- 获取List集合中的重复数据和重复次数(适用于有着连续的相同数据项时)
- Leetcode 149. Max Points on a Line
- hdu3294 manacher算法
- Android蓝牙4.0之GATT
- J2EE常见路径处理
- Python 模块学习 logging
- setTextColor设置
- 常用socket函数
- MFC使用mscomm串口通信
- android的跑马灯效果
- 语料库