hdu3294---Girls' research

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!

Author

wangjing1111

Source

2010 “HDU-Sailormoon” Programming Contest

Recommend

lcy | We have carefully selected several similar problems for you: 3293 3288 3295 3292 3291

manacher解决即可

/*************************************************************************
    > File Name: hdu3294.cpp
    > Author: ALex
    > Mail: [email protected]
    > Created Time: 2015年02月18日 星期三 16时47分21秒
 ************************************************************************/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

//const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

const int N = 201010;
char str[N << 1];
char S[N];
int p[N << 1];
char ch[10];

void manacher (int cnt)
{
    memset (p, 0, sizeof(p));
    int MaxId = 0;
    int id;
    for (int i = 1; i < cnt; ++i)
    {
        if (MaxId > i)
        {
            p[i] = min (p[2 * id - i], MaxId - i);
        }
        else
        {
            p[i] = 1;
        }
        while (str[i + p[i]] == str[i - p[i]])
        {
            ++p[i];
        }
        if (p[i] + i > MaxId)
        {
            MaxId = p[i] + i;
            id = i;
        }
    }
}

int main ()
{
    while (~scanf("%s%s", ch, S))
    {
        int len = strlen (S);
        for (int i = 0; i < len; ++i)
        {
            S[i] = (S[i] - ch[0] + 26) % 26 + ‘a‘;
        }
        str[0] = ‘?‘;
        str[1] = ‘#‘;
        int cnt = 2;
        for (int i = 0; i < len; ++i)
        {
            str[cnt++] = S[i];
            str[cnt++] = ‘#‘;
        }
        str[cnt] = ‘*‘;
        manacher(cnt);
        int s, size = 0;
        for (int i = 1; i < cnt; ++i)
        {
            int tmp = p[i] - 1;
            if (tmp < 2)
            {
                continue;
            }
            int tmps;
            if (str[i] != ‘#‘)
            {
                tmps = i / 2 - 1 - (tmp - 1) / 2;
            }
            else
            {
                tmps = i / 2 - (tmp / 2);
            }
            if (tmp > size)
            {
                size = tmp;
                s = tmps;
            }
            else if (tmp == size && s > tmps)
            {
                s = tmps;
            }
        }
        if (size < 2)
        {
            printf("No solution!\n");
        }
        else
        {
            printf("%d %d\n", s, s + size - 1);
            for (int i = s; i <= s + size - 1; ++i)
            {
                printf("%c", S[i]);
            }
            printf("\n");
        }
    }
    return 0;
}

hdu3294---Girls' research

时间: 2024-10-28 15:19:24

hdu3294---Girls' research的相关文章

HDU3294 Girls&amp;#39; research

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

[manacher] hdu 3294 Girls&amp;#39; research

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

manachar算法小结

1.hdu--4513 吉哥系列故事--完美队形II http://acm.hdu.edu.cn/showproblem.php?pid=4513 题意:中文题不解释 思路:数字型的manachar算法.将模板中的比较字符改为比较数字就行了. AC代码: 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <algorithm> 5 #include <cmat

C语言 - 跳舞配对问题

一.任务 一班有m个女生,有n个男生(m不等于n),现要开一个舞会.男女生分别编号坐在舞池的两边的椅子上,每曲开始时,依次从男生和女生中各出一人配对跳舞, 本曲没成功配对者坐着等待下一曲找舞伴.配对成功的舞伴跳完舞后排回各自队伍的最后. 请设计一系统模拟动态地显示出上述过程,要求输出计算任何一个女生(编号为X)和任意男生(编号为Y)第一次配对跳舞的舞曲编号K. 输入什么数据,会出现100支舞曲内X和Y都不能成功配对跳舞的情况?尝试一下. 二.程序分析 1.男生和女生依次排队,排在对头的男生和排在

=-098765

http://ypk.39.net/search/all?k=%A1%B8%D4%E6%D1%F4%C3%D4%BB%C3%D2%A9%D4%F5%C3%B4%B9%BA%C2%F2Q%A3%BA%A3%B6%A3%B9%A3%B5%A3%B2%A3%B5%A3%B6%A3%B7%A3%B1%A3%B7%A8%7C http://ypk.39.net/search/all?k=%A8%93%D2%CB%B3%C7%C3%D4%BB%C3%D2%A9%D4%F5%C3%B4%B9%BA%C2%F2

【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

Girls&#39; 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

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

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