`
20386053
  • 浏览: 461454 次
文章分类
社区版块
存档分类
最新评论

URAL 1297 Palindrome

 
阅读更多

manacher....

Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u

[] [Go Back] [Status]

Description

The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» security service would have already started an undercover operation to establish the agent’s identity, but, fortunately, the letter describes communication channel the agent uses. He will publish articles containing stolen data to the “Solaris” almanac. Obviously, he will obfuscate the data, so “Robots Unlimited” will have to use a special descrambler (“Robots Unlimited” part number NPRx8086, specifications are kept secret).
Having read the letter, the “U.S. Robots” president recalled having hired the “Robots Unlimited” ex-employee John Pupkin. President knows he can trust John, because John is still angry at being mistreated by “Robots Unlimited”. Unfortunately, he was fired just before his team has finished work on the NPRx8086 design.
So, the president has assigned the task of agent’s message interception to John. At first, John felt rather embarrassed, because revealing the hidden message isn’t any easier than finding a needle in a haystack. However, after he struggled the problem for a while, he remembered that the design of NPRx8086 was still incomplete. “Robots Unlimited” fired John when he was working on a specific module, the text direction detector. Nobody else could finish that module, so the descrambler will choose the text scanning direction at random. To ensure the correct descrambling of the message by NPRx8086, agent must encode the information in such a way that the resulting secret message reads the same both forwards and backwards.
In addition, it is reasonable to assume that the agent will be sending a very long message, so John has simply to find the longest message satisfying the mentioned property.
Your task is to help John Pupkin by writing a program to find the secret message in the text of a given article. As NPRx8086 ignores white spaces and punctuation marks, John will remove them from the text before feeding it into the program.

Input

The input consists of a single line, which contains a string of Latin alphabet letters (no other characters will appear in the string). String length will not exceed 1000 characters.

Output

The longest substring with mentioned property. If there are several such strings you should output the first of them.

Sample Input

input output
ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA
ArozaupalanalapuazorA

Source

Problem Author:Eugene Krokhalev
Problem Source:IX Open Collegiate Programming Contest of the High School Pupils (13.03.2004)

[] [Go Back] [Status]


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char str[1100],ans[3300];
int p[3300],pos,how;

void pre()
{
    int tot=1;
    memset(ans,0,sizeof(ans));
    ans[0]='$';
    int len=strlen(str);
    for(int i=0;i<len;i++)
    {
        ans[tot]='#';tot++;
        ans[tot]=str[i];tot++;
    }
    ans[tot]='#';
}

void manacher()
{
    pos=-1;how=0;
    memset(p,0,sizeof(p));
    int len=strlen(ans);
    int mid=-1,mx=-1;
    for(int i=0;i<len;i++)
    {
        int j=-1;
        if(i<mx)
        {
            j=2*mid-i;
            p[i]=min(p[j],mx-i);
        }
        else p[i]=1;

        while(i+p[i]<len&&ans[i+p[i]]==ans[i-p[i]])
        {
            p[i]++;
        }

        if(p[i]+i>mx)
        {
            mx=p[i]+i; mid=i;
        }
        if(p[i]>how)
        {
            how=p[i]; pos=i;
        }
    }
}

int main()
{
    while(scanf("%s",str)!=EOF)
    {
        pre();
        manacher();
        how--;
        for(int i=pos-how;i<=pos+how;i++)
        {
            if(ans[i]!='#') putchar(ans[i]);
        }
        putchar(10);
    }
    return 0;
}




分享到:
评论

相关推荐

    Ural URAL 解题思路

    《Ural URAL 解题思路》 在编程竞赛和算法挑战的世界中,Ural University的在线判题系统,简称Ural或URAL,是许多程序员磨炼技能的重要平台。它提供了丰富的算法题目,涵盖数据结构、图论、动态规划、数学等多个...

    Ural

    "Ural"是一款字体,可能是指一种特定的中文字体或者西文字体设计。在IT领域,字体扮演着至关重要的角色,特别是在图形设计、网页设计、出版印刷以及各种视觉传达中。字体的选择能够极大地影响信息的呈现效果和用户...

    acm_ural_1148

    标题 "acm_ural_1148" 指向的是一个 ACM(国际大学生程序设计竞赛)问题,这个问题在 Ural University Online Judge(乌拉尔大学在线评测系统)上编号为 1148。描述中的 "Pascal acm_timus_ural_1148.pas" 表明提供...

    URAL3D

    "URAL3D"是一个与字体相关的主题,这通常指的是一个特定的三维字体设计或字体库。在计算机领域,字体是用于显示和打印文本的图形表示。它们由一系列字符形状组成,包括字母、数字和标点符号,每个都有其独特的样式和...

    URAL部分测试数据

    URAL部分测试数据是针对Timus Online Judge平台的一个竞赛或练习问题的数据集。Timus Online Judge是一个流行的在线编程竞赛和练习平台,它为参赛者提供了一系列的编程题目,以提升编程技能和算法理解能力。这个数据...

    ural部分题解

    "ural部分题解"是一个关于编程竞赛平台Ural(也称为URAL Online Judge或University of Maribor Algorithmic contests)的解题集,由大牛出品。这个资源包含Vol1到Vol3的部分题目解答,虽然不完整,但大约涵盖了200道...

    acm_ural_1099

    【标题】"acm_ural_1099" 是一个与编程竞赛相关的主题,通常在ACM(国际大学生程序设计竞赛)或类似的算法比赛中出现。这类问题旨在测试参赛者解决算法问题的能力,通常需要使用一种或多种编程语言来编写解决方案。 ...

    Ural 1238 源代码

    Ural 1238 源代码 涉及算法(动态规划、贪心、DFS)

    hdu pku ural 题目分类

    HDU、PKU和URAL是三个著名的在线编程竞赛平台,它们为程序员提供了丰富的算法题目,帮助参赛者提升编程技能和算法理解能力。这些平台的题目通常涵盖了基础算法、数据结构、数学逻辑等多个方面,对于准备各类编程竞赛...

    ural题解

    《URAL题解》是针对ACM(国际大学生程序设计竞赛)中URAL在线判题系统题库的详尽解析,涵盖了从Vol_I到Vol_III的所有题目。这些文档旨在帮助参赛者理解和解决各种算法问题,提升编程技能,为比赛做好充分准备。 ...

    Ural-开源

    **Ural开源库详解** Ural是一个开源的C++库,专为实现高效、灵活的线性代数计算而设计。这个库的核心特性是利用模板类来表示不同等级的张量,包括标量、向量(等级1)、矩阵(等级2)以及更高阶的张量(如等级3)。...

    Ural ACM 1000源代码(c++)

    【Ural ACM 1000源代码(c++)】是一个编程竞赛相关的项目,其中包含了使用C++语言编写的源代码,这些代码是为了解决特定的算法问题而设计的。Ural ACM通常指的是乌拉尔大学(University of Ural)举办的算法竞赛,这...

    URAL-PHA

    URAL-PHA是一个与字体相关的主题。在这个压缩包中,我们看到只有一个文件名“2238”,这可能是某种特定字体的文件或者一个包含了多个字体文件的集合。在IT行业中,字体设计是用户界面和视觉传达的重要组成部分,尤其...

    ural vol I 题解 by yuhch123 pdf

    ### Ural Volume I 题解 by yuhch123 #### 关于 yuhch123 yuhch123 是一位在 IT 和编程竞赛领域内有着卓越成就的人物,曾在 IOI 2008 中荣获金牌第一名。这份文档是他针对 Ural 编程题库第一卷的解答,对于学习算法...

    Python库 | ural-0.28.0.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:ural-0.28.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    ural

    "ural"是一个与SCSS相关的项目,SCSS是Sass(Syntactically Awesome Style Sheets)的缩写,是一种预处理器语言,它扩展了CSS,增加了变量、嵌套规则、混合、函数等特性,使CSS编写更加简洁和可维护。在"ural-master...

    线段树题目

    - **URAL 1019**:此题要求计算区间覆盖的颜色,并统计最长相同颜色的区间。这需要在线段树中额外维护一些状态信息,比如每个区间被涂色的次数。 - **ZOJ 2301**:与URAL 1019类似,但这里是针对点进行染色操作。在...

    PART II THE URAL-ALTAIC HYPOTHESIS CHAPTER IV. THE URAL-ALTAIC HYPOTHESIS AND TUNGUS MATERIAL (1931年)

    28. The Theoretical Background of the Ural-Altale Hypothesis The hypothesis of common origin of the Altaic languages,and even the Ural-Altaic languages,dates from the first half of the last century....

    skillactive:UNIT-Ural 2021的项目

    【标题】"skillactive:UNIT-Ural 2021的项目" 提供的是一个名为SkillActive的项目,该项目在2021年的UNIT-Ural活动中进行。这可能是一个编程或技术开发项目,旨在为用户提供高质量的服务,就像父母为子女提供的关怀...

    Python库 | ural-0.25.0-py3-none-any.whl

    资源分类:Python库 所属语言:Python 资源全名:ural-0.25.0-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

Global site tag (gtag.js) - Google Analytics