Girls' research HDU - 3294(马拉车水题)
题意:
求最长回文串 长度要大于等于2 且输出起点和终点 输出回文串字符 这个字符还是要以给出的字符为起点a 输出
解析:
分析一下s_new串就好了
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
char s[maxn], s_new[maxn<<];
int p[maxn<<];
int tmp;
int init()
{
int len = strlen(s);
s_new[] = '$';
s_new[] = '#';
int j = ;
for(int i=; i<len; i++)
s_new[j++] = s[i], s_new[j++] = '#';
s_new[j++] = '\0';
return j;
} int manacher()
{
int len = init();
int max_len = -;
int id, mx = ;
for(int i=; i<len; i++)
{
if(i < mx)
p[i] = min(p[*id - i], mx - i);
else
p[i] = ;
while(s_new[i-p[i]] == s_new[i+p[i]])
p[i]++;
if(mx < i+p[i])
{
mx = i+p[i];
id = i;
}
if(max_len < p[i] - )
max_len = p[i] - , tmp = i;
}
return max_len;
} char c;
int main()
{
while(~scanf("%c%s", &c, s))
{
getchar();
int max_len = manacher();
if(max_len < )
printf("No solution!\n");
else
{
int a = (tmp-p[tmp])/, b = (tmp-p[tmp])/+p[tmp]-;
printf("%d %d\n", a, b);
for(int i=a; i<=b; i++)
{
if(s[i] >= c)
printf("%c", s[i] - c + 'a');
else
printf("%c", 'z' - c + s[i] + );
}
printf("\n"); }
} return ;
}
Girls' research HDU - 3294(马拉车水题)的更多相关文章
- (回文串 Manacher )Girls' research -- hdu -- 3294
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS Memory Limit:32 ...
- Girls' research - HDU 3294 (Manacher处理回文串)
题目大意:给以一个字符串,求出来这个字符串的最长回文串,不过这个字符串不是原串,而是转换过的,转换的原则就是先给一个字符 例如 'b' 意思就是字符把字符b转换成字符 a,那么c->b, d-& ...
- hdu 5210 delete 水题
Delete Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...
- hdu 1251 (Trie水题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- HDU 4493 Tutor 水题的收获。。
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...
- hdu 4802 GPA 水题
GPA Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...
- HDU 3294 Manacher模版题
点击打开链接 题意:求最长回文子串所在的区间,然后第一个字符代表a,以后的顺推,最后输出这个区间顺推后的串 思路:Manacher轻松水过.记录下最长回文串的位置和长度即可了,然后输出时自己处理一下, ...
- hdu 1015 Safecracker 水题一枚
题目链接:HDU - 1015 === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein s ...
随机推荐
- 【日常训练】数据中心(CSP 201812-4)
分析 题目实际上是在要在给定的边上构建出一个树,使得这个树的最长边尽可能小. 这实际上是最小生成树的性质(反证法).问题从而得到解决. 代码 /* * Code name => csp20181 ...
- JTree实现电脑资源管理器
0.前言 最近老师布置了一项用Java写资源管理器的任务,一开始以为简单,但是实际操作起来,却发现网上的资源用起来相对生疏.在使用中,我也遇到了许多问题,虽然不能像其他博主一样,写的非常齐全,但我还是 ...
- 相机标定与矫正opencv+MATLAB
博客转载自:http://blog.csdn.net/Loser__Wang/article/details/51811347 本文目的在于记录如何使用MATLAB做摄像机标定,并通过opencv进行 ...
- 学习python,第一篇
name = "danie" name2 = name print(name,name2) name = "itxpl" print(name,name2) 结 ...
- linux-shell-screen后台调用-后台运行脚本和命令-仿start命令-伪窗口界面
序 我比较熟练bat.cmd脚本.刚接触使用shell时,总会习惯想用windows窗口界面来套用shell脚本.于是找到screen后台命令,它可以交互shell脚本,保持后台运行.但是在批处理ba ...
- Discuz3.3精仿小米风格整站模板制作——1、新建模板方案
术语说明: 模板——模板是一堆按照规定命名方式的html文件,用于指定整个论坛不同页面的外观. 标签——标签和模板共同作用以实现论坛换肤功能,其中标签主要控制页面显示什么数据,显示多少条等. 风格—— ...
- python基础网络编程--转
python之网络编程 本地的进程间通信(IPC)有很多种方式,但可以总结为下面4类: 消息传递(管道.FIFO.消息队列) 同步(互斥量.条件变量.读写锁.文件和写记录锁.信号量) 共享内存(匿名的 ...
- python处理数据pandas视频资料
python强大数据处理工具pandas视频资料:https://pan.baidu.com/s/17VRd1cgFaKi20drfCgZ8Gg
- 前端_JavaScript
目录 JavaScript的基础 引入方式 JS的变量.常量和标识符 JS的数据类型 运算符 流程控制 JavaScript的对象 String对象 Array对象 Date对象 Math对象 Fun ...
- 软件工程-东北师大站-第十次作业(PSP)
1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 4.本周PSP饼状图