Girls' research

hdu3294:http://acm.hdu.edu.cn/showproblem.php?pid=3294

题意:就是给你一个串,然后求一个最长的回文串,输出起点及串,但是这里在之前要转化一下。

题解:转化一下,就是简单的Manacher算法。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 const int N=2e6+440;
 7 char str1[N],str[N<<1];
 8 int rad[N];
 9 char temp;
10 void Manacher(int *rad,char *str,int n){
11    int i,mx=0,id;
12    for(int i=1;i<n;i++){
13     if(mx>i){
14     rad[i]=min(rad[2*id-i],mx-i);
15    }
16    else
17     rad[i]=1;
18     for(;str[i-rad[i]]==str[i+rad[i]];rad[i]++){
19         if(rad[i]+i>mx){
20             mx=rad[i]+i;
21             id=i;
22         }
23      }
24    }
25 }
26
27 int main(){
28   while(~scanf("%c %s",&temp,str1)){
29        getchar();
30       int nn=strlen(str1);
31         int n=2*nn+2;
32         str[0]=‘$‘;
33       for(int i=0;i<=nn;i++){
34           str[2*i+1]=‘#‘;
35           str[2*i+2]=(str1[i]-temp+26)%26+‘a‘;
36       }
37       memset(rad,0,sizeof(rad));
38       Manacher(rad,str,n);
39       int ans=0,pos=0;
40       for(int i=0;i<=n;i++){
41         if(rad[i]>=3&&rad[i]>ans){
42             ans=rad[i];
43             pos=i;
44         }
45       }
46        ans--;
47       if(ans==-1)printf("No solution\n");
48       else{
49             int s=pos-ans+1,e=pos+ans-1;
50              printf("%d %d\n",s/2-1,e/2-1);
51         for(int i=pos-ans+1;i<=pos+ans-1;i++){
52             if(str[i]==‘#‘)continue;
53             printf("%c",str[i]);
54         }
55         puts("");
56       }
57   }
58 }

Girls' research

时间: 2024-10-28 18:28:07

Girls' research的相关文章

Girls&#39; research(manacher)

Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1160    Accepted Submission(s): 448 Problem Description One day, sailormoon girls are so delighted that they intend to research a

(回文串 Manacher )Girls&#39; research -- hdu -- 3294

http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3294 Description One day, sailormoon girls are so delighted that they intend to res

HDU 3294 Girls&#39; research (Manacher算法 + 记录区间)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3294 题目大意:输入一个字符ch和一个字符串,问如果把ch当作'a'的话,字符串的每个字符也要做相应变化,如b aa,若b为'a',则b前面的a就为'a'前面的'z',这里是循环表示,输出字符串的最长回文子串,如果最长回文子串串长为1,输出No solution! 几乎是模板题,唯一的特别之处就是要输出回文串字符,所以要记录max(Mp[i])对应的在原串中的字符区间,根据Manacher算法的步骤

HDU 3294 Girls&#39; research

题目地址 manacher 1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int Nmax=200005; 6 char s[Nmax]; 7 char str[Nmax*2+10]; 8 int p[Nmax*2+10]; 9 int hashh[Nmax*2+10]; 10 int id; 11 int maxlen; 12 i

HDU 3294 (Manacher) Girls&#39; research

变形的求最大回文子串,要求输出两个端点. 我觉得把'b'定义为真正的'a'是件很无聊的事,因为这并不会影响到最大回文子串的长度和位置,只是在输出的时候设置了一些不必要的障碍. 另外要注意一下原字符串s1中的字符在预处理以后的字符串s2中对应的坐标关系,这样输出的时候就可以照着这个关系转化. 轻松1A,嘿嘿 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5

【hdu3294】Girls&#39; research——manacher

Problem Description One day, sailormoon girls are so delighted that they intend to research about palindromic strings. Operation contains two steps: First step: girls will write a long string (only contains lower case) on the paper. For example, "abc

Hdu 3294 Girls&#39; research (manacher 最长回文串)

题目链接: Hdu 3294  Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.......,a == z. 问最长回文串所在区间,以及最长回文串所表示的明码. 解题思路: 字符串长度[1,200000],用manacher算法很轻松就搞定了. get√新技能请点击me 1 #include <cstdio> 2 #include <cstring> 3 #includ

[manacher] hdu 3294 Girls&#39; research

题意: 给一个字符x代表真实的a 然后输出的时候转换 然后就是求最长回文子串的串是什么 长度要大于1 思路: 就是裸的manacher,弄清楚下标的转换关系就好了 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #include"queue" #include"algorithm" #inc

HDU----(3294)Girls&#39; research(manacher)

Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 537    Accepted Submission(s): 199 Problem Description One day, sailormoon girls are so delighted that they intend to research abo