hdu3294-Girls' research
http://acm.hdu.edu.cn/showproblem.php?pid=3294
找最长的回文串的基本题目,用马拉车算法。最核心的地方是len【i】的求法,利用之前的len,并且maxr的思想。
#include <iostream>
#include <cstdio>
#include <cstring>using namespace std;const int maxn = 1e6;
int len[maxn];
int n, N;
char S[maxn], s[maxn], ch[10];
int maxr, p, idx;void preAndGetLen() {for(int i = 1; i <= n; i++){S[2 * i - 1] = '#';S[2 * i] = s[i];}S[2 * n + 1] = '#';N = 2 * n + 1;maxr = -1;p = -1;len[0] = 0;idx = 0;for(int i = 1; i <= N; i++) {if(maxr < i) {len[i] = 1;} else {len[i] = min(maxr - i + 1, len[2 * p - i]);}while(i + len[i] <= N && i - len[i] >= 1 && S[i + len[i]] == S[i - len[i]]) {len[i]++;}if(i + len[i] - 1 > maxr) {maxr = i + len[i] - 1;p = i;}if(len[i] > len[idx]) idx = i;}
}
void out(char t) {int no = ((t - 'a' - ch[0] + 'a') % 26 + 26) % 26;printf("%c", (char)(no +'a'));
}int main(){while(scanf("%s %s", ch, s + 1) != EOF){n = strlen(s + 1);preAndGetLen();int ans = (2 * len[idx] - 1) / 2;if(ans > 1){int pp = (idx + 1) / 2;if(ans % 2 == 0) {printf("%d %d\n", pp - ans / 2 - 1, pp + ans / 2 - 1 - 1);} else {printf("%d %d\n", pp - ans / 2 - 1, pp + ans / 2 - 1);}for(int i = idx - len[idx] + 1; i <= idx + len[idx] - 1; i++) {if(S[i] != '#') {out(S[i]);}}printf("\n");} else {printf("No solution!\n");}}return 0;
}
hdu3294-Girls' research相关推荐
- 【hdu3294】Girls' research
虽然这是个manacher模板题,可是这毕竟是我第一次打manacher2333333 #include<iostream> #include<cstring> #includ ...
- kuangbin带你飞专题合集
题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...
- 算法学习经典例题整理
陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...
- kuangbin带你飞 专题1-23 题单
kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...
- 老鱼的-kuangbin专题题解
kuangbin专题问题一览 专题一 简单搜索 POJ 1321 棋盘问题 POJ 2251 Dungeon Master POJ 3278 Catch That Cow POJ 3279 Flipt ...
- [manacher] hdu 3294 Girls#39; research
题意: 给一个字符x代表真实的a 然后输出的时候转换 然后就是求最长回文子串的串是什么 长度要大于1 思路: 就是裸的manacher,弄清楚下标的转换关系就好了 代码: #include" ...
- 各大知名企业的Research展示
大公司為了要拉開彼此的差距, 除了專注於目前的產品外, 都會為了未來做準備, 而這些研究通常都會做一個 Research 的專區來呈現成果, 如下述列表: Google Research Yahoo! ...
- PAT1036:Boys vs Girls
1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This ti ...
- MediaPipe:Google Research 开源的跨平台多媒体机器学习模型应用框架
作者 | MediaPipe 团队 来源 | TensorFlow(ID:tensorflowers) [导读]我爱计算机视觉(aicvml)CV君推荐道:"虽然它是出自Google Res ...
- Google Research进军蛋白质结构预测:为Pfam数据库新增680万标注数据
视学算法报道 编辑:LRS [新智元导读]用深度学习模型来预测蛋白质的结构和功能已经取得了不小的进展,但还缺乏优质的数据.最近Google开源了一个模型ProtENN,提供了680万条蛋白质结 ...
最新文章
- 如何造出逼真图像?南洋理工Zheng博士论文《基于深度生成学习的逼真图像合成》197页pdf阐述视觉合成工作...
- SPOJ - QTREE5 Query on a tree V 边分治
- 携程基于云的软呼叫中心及客服平台架构实践
- 统计学习方法第十五章作业:SVD矩阵分解 代码实现 及其在推荐的应用和矩阵压缩意义
- 函数sigsuspend
- 长文详解基于并行计算的条件随机场CRF
- 一个计算两个日期间隔的算法
- javacript 字典
- 涉及到整型参数时,没有初始化时,Debug下可以运行,但是Release下不行
- 力扣——实现 strStr()
- 【Java基本功】一文读懂final关键字的用法 1
- java服务端验证框架_SpringBoot服务端数据校验过程详解
- python中换行的转义字符_Python语言中表示换行的转义字符是____________。(2.5分)_学小易找答案...
- 基于粒子群优化深度核极限学习机的故障诊断方法
- 大数据数据挖掘与云计算-认识大数据
- 联邦学习纵向逻辑回归公式推导
- 名帖203 米芾 行书《行书帖选》
- 牛客入门编程—金字塔图案
- c语言把下划线换成空格,python - 如何用下划线替换空格,反之亦然?
- Python 爬虫 之 爬虫的一些基本知识和基本操作(爬取视频、图片、获取网页源码等)整理