hdu 3294 Girls' research(manacher)
First step: girls will write a long string (only contains lower case) on the paper. For example, "abcde", but 'a' inside is not the real 'a', that means if we define the 'b' is the real 'a', then we can infer that 'c' is the real 'b', 'd' is the real 'c' ……, 'a' is the real 'z'. According to this, string "abcde" changes to "bcdef".
Second step: girls will find out the longest palindromic string in the given string, the length of palindromic string must be equal or more than 2.
Each case contains two parts, a character and a string, they are separated by one space, the character representing the real 'a' is and the length of the string will not exceed 200000.All input must be lowercase.
If the length of string is len, it is marked from 0 to len-1.
If you find one, output the start position and end position of palindromic string in a line, next line output the real palindromic string, or output "No solution!".
If there are several answers available, please choose the string which first appears.
题意:给你一个字符表示真正的a 然后要你求解码以后的最长回文序列
思路:先manacher处理一下 然后从头到尾解码即可
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define ll long long int
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int p[]; //注意数组的大小 要开2倍
void manacher(string s){
string temp="";
temp+="$#";
int len=s.length();
for(int i=;i<len;i++){
temp+=s[i];
temp+="#";
}
len=temp.length();
int po=; int mx=;
for(int i=;i<len;i++){
p[i]=mx>i?min(p[*po-i],mx-i):;
while(temp[p[i]+i]==temp[i-p[i]]) p[i]++;
if(i+p[i]>mx){
mx=p[i]+i;
po=i;
}
}
}
int main(){
ios::sync_with_stdio(false);
char real;
string s;
while(cin>>real>>s){
manacher(s);
int len=s.length();
int ans=;
int sp=-;
for(int i=;i<*len+;i++){
if(ans<p[i]-){
ans=p[i]-;
sp=(i-p[i])/;
}
}
if(sp==-){
cout<<"No solution!"<<endl;
}else{
cout<<sp<<" "<<sp+ans-<<endl;
for(int i=sp;i<=sp+ans-;i++)
cout<<char((s[i]-real+)%+'a');
cout<<endl;
}
}
return ;
}
hdu 3294 Girls' research(manacher)的更多相关文章
- Hdu 3294 Girls' research (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
- HDU 3294 Girls' research(manachar模板题)
Girls' researchTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- HDU 3294 Girls' research
题目地址 manacher #include<cstdio> #include<string.h> #include<algorithm> using namesp ...
- Girls' research(manacher)
Girls' research Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- 【 HDU3294 】Girls' research (Manacher)
BUPT2017 wintertraining(15) #5F HDU - 3294 题意 给定字母x,字符串变换一下: 'x'-1 -> 'z', 'x'->'a', 'x'+1-> ...
- HDU3294 Girls' research —— Manacher算法 输出解
题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others) M ...
- [manacher] hdu 3294 Girls' research
题意: 给一个字符x代表真实的a 然后输出的时候转换 然后就是求最长回文子串的串是什么 长度要大于1 思路: 就是裸的manacher,弄清楚下标的转换关系就好了 代码: #include" ...
- hdu 3294 Girls' research
#include<stdio.h> #include<string.h> #define MAX 200020 char s[MAX],ss[MAX*2],str[2]; in ...
- hdu3294 Girls' research manacher
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...
随机推荐
- h5-语义化标签
###1.语义化标签 在h5之前,在开发过程中大量div的id名称重复,例如div id="footer"来标记页脚内容,所以html5元素引入了语义化标签(一组新的片段类元素) ...
- vue传参二
<template> <ul> <li v-for="(value,key,index) in list" :key="index" ...
- Oracle查询数据库编码
select userenv('language') from dual
- 谈谈git/github
先说git/github操作 ->关于git/github操作的好文章已经非常多,如: github使用指南 廖雪峰的git教程 本文的目的在于,积累自己平时相关的操作和想法,记录下来,形成自己 ...
- re正则表达式-1
匹配/查找/替换/分割函数: import re re.match('aa','aabbcc') 返回对象中span为开始位置和结束位置 re.match('aa','bbaacc') #返回值为No ...
- Antd & ice
Antd & ice Angular https://github.com/NG-ZORRO/ng-zorro-antd https://ng.ant.design/docs/introduc ...
- MySQL中and和or的优先级的问题
参考资料: 关于MySQL中AND和OR的优先级的问题 SQL语句中的AND和OR执行顺序问题 MySQL带OR关键字的多条件查询
- 莫烦scikit-learn学习自修第五天【训练模型的属性】
1.代码实战 #!/usr/bin/env python #!_*_ coding:UTF-8 _*_ from sklearn import datasets from sklearn.linear ...
- vue循環語句
迭代數組: v-for="site in sites”,sites表示源數組名,site表示數組元素: 迭代對象: v-for=“value in Object”, v-for=" ...
- SpringBoot之文件下载
package org.springboot.controller; import org.springboot.constant.Constant; import org.springframewo ...