Girls' research
hdu3294:http://acm.hdu.edu.cn/showproblem.php?pid=3294
题意:就是给你一个串,然后求一个最长的回文串,输出起点及串,但是这里在之前要转化一下。
题解:转化一下,就是简单的Manacher算法。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e6+;
char str1[N],str[N<<];
int rad[N];
char temp;
void Manacher(int *rad,char *str,int n){
int i,mx=,id;
for(int i=;i<n;i++){
if(mx>i){
rad[i]=min(rad[*id-i],mx-i);
}
else
rad[i]=;
for(;str[i-rad[i]]==str[i+rad[i]];rad[i]++){
if(rad[i]+i>mx){
mx=rad[i]+i;
id=i;
}
}
}
} int main(){
while(~scanf("%c %s",&temp,str1)){
getchar();
int nn=strlen(str1);
int n=*nn+;
str[]='$';
for(int i=;i<=nn;i++){
str[*i+]='#';
str[*i+]=(str1[i]-temp+)%+'a';
}
memset(rad,,sizeof(rad));
Manacher(rad,str,n);
int ans=,pos=;
for(int i=;i<=n;i++){
if(rad[i]>=&&rad[i]>ans){
ans=rad[i];
pos=i;
}
}
ans--;
if(ans==-)printf("No solution\n");
else{
int s=pos-ans+,e=pos+ans-;
printf("%d %d\n",s/-,e/-);
for(int i=pos-ans+;i<=pos+ans-;i++){
if(str[i]=='#')continue;
printf("%c",str[i]);
}
puts("");
}
}
}
Girls' research的更多相关文章
- HDU----(3294)Girls' research(manacher)
Girls' research Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)T ...
- Girls' research(manacher)
Girls' research Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- HDU 3294 Girls' research(manachar模板题)
Girls' researchTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- (回文串 Manacher )Girls' research -- hdu -- 3294
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS Memory Limit:32 ...
- HDU3294 Girls' research —— Manacher算法 输出解
题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others) M ...
- Hdu 3294 Girls' research (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
- 回文串--- Girls' research
HDU 3294 Problem Description One day, sailormoon girls are so delighted that they intend to resear ...
- hdu 3294 Girls' research(manacher)
Problem Description One day, sailormoon girls are so delighted that they intend to research about pa ...
- hdu3294 Girls' research manacher
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...
- kuangbin专题十六 KMP&&扩展KMP HDU3294 Girls' research
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...
随机推荐
- 使用QEMU调试Linux内核代码
http://blog.chinaunix.net/uid-20729583-id-1884617.html http://www.linuxidc.com/Linux/2014-08/105510. ...
- Publisher/Subscriber(发布/订阅者)消息模式开发流程
该模式的作用是发布者和订阅者 可以相互发送消息 发布者和订阅者都充当 生产者和消费者 发布者 package publisher.to.subscriber; import java.awt.font ...
- Chapter 5 - How to Detect the Collisions
Chapter 5 - How to Detect the Collisions Our hero can fire bullets now, but the bullets are only vis ...
- iOS网络层架构设计分享
前言 前些天帮公司做了网络层的重构,当时就想做好了就分享给大家,后来接着做了新版本的需求,现在才有时间整理一下. 之前的网络层使用的是直接拖拽导入项目的方式导入了AF,然后还修改了大量的源码,时隔2年 ...
- 在命令行中如何访问Program Files文件夹(转)
通常来说Program Files文件夹位于C盘,也就是C:\Program File.为了保证兼容性,在命令行中通常使用环境变量%ProgramFiles%来表示Program Files的具体路径 ...
- 通过扫描包路径获取包内class
public static Set<Class<?>> getClasses(ClassLoader classLoader, String pack) { Set<Cl ...
- 浅析MySQL中exists与in的使用 (写的非常好)
转自http://sunxiaqw.blog.163.com/blog/static/990654382013430105130443/ exists对外表用loop逐条查询,每次查询都会查看exis ...
- wamp5.2 升级到wamp5.3 (转载)
1. 停止WAMP服务器. 2. 去网站windows.php.net 下载php5.3.5 the VC6 Thread Safe build. 不要下载THE INSTALLER. 3. 在 ...
- MVVM模式应用 之加载Pivot的数据
在Pivot布局里,在进入页面时,不想页面数据全部加载,而是移动到哪个privotItem,加载那个privotItem的值. 这时我们先给pivot绑定一个command. <phone:Pi ...
- 5shift shell
echo offcopy %systemroot%\system32\taskmgr.exe %systemroot%\system32\sethc.execopy %systemroot%\syst ...