zoukankan      html  css  js  c++  java
  • hdu 3294 Girls' 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, "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.
     
    Input
    Input contains multiple cases.
    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.
     
    Output
    Please execute the operation following the two steps.
    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.
     
    Sample Input
    b
    babd
    a abcd
     
    Sample Output
    0 2
    aza
    No solution!

    题意:给你一个字符表示真正的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[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int dir[4][2]={1,0 ,0,1 ,-1,0 ,0,-1};
    int dirs[8][2]={1,0 ,0,1 ,-1,0 ,0,-1, -1,-1 ,-1,1 ,1,-1 ,1,1};
    const int inf=0x3f3f3f3f;
    const ll mod=1e9+7;
    int p[400007]; //注意数组的大小 要开2倍 
    void manacher(string s){
        string temp="";
        temp+="$#";
        int len=s.length();
        for(int i=0;i<len;i++){
            temp+=s[i];
            temp+="#";
        }
        len=temp.length();
        int po=0; int mx=0;
        for(int i=0;i<len;i++){
            p[i]=mx>i?min(p[2*po-i],mx-i):1;
            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=1;
            int sp=-1;
            for(int i=0;i<2*len+2;i++){
                if(ans<p[i]-1){
                    ans=p[i]-1;
                    sp=(i-p[i])/2;
                }
            }
            if(sp==-1){
                cout<<"No solution!"<<endl;
            }else{
                cout<<sp<<" "<<sp+ans-1<<endl;
                for(int i=sp;i<=sp+ans-1;i++)
                    cout<<char((s[i]-real+26)%26+'a');
                cout<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    cocospods 卡在 Analyzing dependencies
    android px、sp、dp之间的互转
    Android 4.4环境搭建——Android SDK下载与安装
    我心中的核心组件(可插拔的AOP)~大话开篇及目录
    EF架构~AutoMapper对象映射工具简化了实体赋值的过程
    我心中的核心组件(可插拔的AOP)~第二回 缓存拦截器
    EF架构~为EF DbContext生成的实体添加注释(T5模板应用)
    品味编程~底层开发人员应该这样设计一个字体类
    Study notes for Clustering and K-means
    深入理解Oracle索引(25):一招鲜、吃遍天之单字段索引创建思路
  • 原文地址:https://www.cnblogs.com/wmj6/p/10600128.html
Copyright © 2011-2022 走看看