hdu-3249-Girls' research -mancher
来源:互联网 发布:云计算怎么赚钱 编辑:程序博客网 时间:2024/06/05 18:38
题目传送门:https://vjudge.net/problem/HDU-3294
就是manacher求一下回文串,同时记录一下起始位置和长度,输出。先进行字母的替换。
感觉,最不好推得是,根据变形后的字符串去找现在字符串的位置。
l = (i - 1)/2 - (ans - 1)/2; r = l + ans - 2;
ac代码:
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cctype>#include <string>#include <vector>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define N 200005#define ll long longusing namespace std;char a[N];char s[2*N];int p[2*N], len, l, r;int manacher(){ int pos = 0, maxr = 0, ans = 0; for(int i = 2; i <= 2*len; i++) { p[i] = i < maxr ? min(p[2*pos-i], maxr -i) : 1; while(s[i+p[i]] == s[i-p[i]]) p[i]++; if(i + p[i] > maxr) maxr = i + p[i], pos = i; if(ans < p[i]) { ans = p[i]; l = (i - 1)/2 - (ans - 1)/2; r = l + ans - 2; } } return ans - 1;}int main(){ char ch; while(scanf("%c %s%*c", &ch, a+1)!=EOF) { len = strlen(a+1); s[0] = '$'; s[1] = '#'; int c = ch; for(int i = 1; i <= len; i++) { s[i*2+1] = '#'; int b = a[i]; s[i*2] = abs(b - c + 26) % 26 + 'a'; } int ans = manacher(); if(ans <= 1) { printf("No solution!\n"); } else { printf("%d %d\n", l, r); for(int i = l+1; i <= r+1; i++) { int b = a[i]; printf("%c", abs(b - c + 26) % 26 + 'a'); } printf("\n"); } } return 0;}
阅读全文
0 0
- hdu-3249-Girls' research -mancher
- hdu 3294 Girls' research
- hdu 3294 Girls' research
- HDU 3294 Girls' research
- hdu 3294 Girls' research
- HDU 3294Girls' research
- [manacher] hdu 3294 Girls' research
- hdu 3294 Girls' research(manacher)
- HDU - 3294 Girls' research(manacher)
- hdu 3294 Girls' research【manacher】
- HDU 3294 Girls’ research Manacher
- HDU 3294 Girls' research 字符串-manacher算法
- HDU 3294 Girls' research (manacher)
- hdu 3294 Girls' research Manacher回文串
- HDU.3294 Girls' research Manacher Algorithm
- Girls' research
- Girls' research
- HDU 3294 Girls' research (Manacher算法 + 记录区间)
- Python 正确重载运算符
- 【盘点】9月值得参加的大数据大会相关会议
- c/c++易错知识点3(引用和指针)(二)
- SQL 语句的使用
- JVM原理
- hdu-3249-Girls' research -mancher
- Leaflet加载百度题图
- VisualSVN-Server-2.7.5安装教程
- problem K.Reisen's sequence
- (转)C语言union(联合体 共用体)
- 移动商城第二篇【页面框架解析】
- JNI技术
- rild 部分系统属性property_set失败的原因分析
- ubuntu的codelite中代码运行后出现/usr/bin/codelite_exec: 22: /usr/bin/codelite_exec