21991_ShakingaString

2022-5-16 18:20| 发布者: Hocassian| 查看: 16| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-8950622421399-Problem List-采集的数据-后羿采集器.html

Pro.ID

21991

Title

Shaking a String

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21991

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    The search engine company Elgoog has started to investigate alternative ways to index data that would allow for large amounts of data to be queried more cleverly than just about containing or not containing a substring. Working on this, the researchers discovered a transformation that has many interesting properties. They decided to call the transformation "shaking".

    Let's consider a string S of length n (2 ≤ n ≤ 1000000) consisting of lowercase Latin letters and the dollar sign ($). The latter is called a guard and has the code less than that of any of the letters. The guard appears only once in the string, in the last position. Then, for any integer k (1 ≤ kn-1, where k is a power of 2), we define the shaken form of S as the string T obtained as follows:

    1) For every cyclic shift of S write out the triple (PRK, POS, LAST), where PRK is the first k characters of the shifted string, POS is the position (counting from zero) of the first letter of S in the shifted string, and LAST is the last character of the shifted string.

    2) Sort the resulting triplets in ascending order , using the following rule to compare the triples: for any two triples C1 = (PRK1, POS1, LAST1) and C2 = (PRK2, POS2, LAST2) we will consider C1 < C2, if PRK1 is lexicographically less than PRK2 or , if they are equal, if POS1 < POS2.

    3) After sorting the triples, write out the values of LASTi in that order. This sequence of letters is the shaken form T.

    Let's consider an example for k = 2:

    The shaken form of a string usually has much simpler probabilistic structure than the original, which allows quite complicated information about S to be extracted from it using relatively simple algorithms. The researchers have accomplished that, but now they have decided it would be a waste to keep both the shaken T and the original S in the database. Using an automated theorem prover, they have learned that an efficient algorithm for extracting S from T must exist. However , they have been unable to derive the algorithm and have turned to you for help.

    输入

    The first line contains the value k and the second line the shaken string T.

    输出

    Description

    The search engine company Elgoog has started to investigate alternative ways to index data that would allow for large amounts of data to be queried more cleverly than just about containing or not containing a substring. Working on this, the researchers discovered a transformation that has many interesting properties. They decided to call the transformation "shaking".

    Let's consider a string S of length n (2 ≤ n ≤ 1000000) consisting of lowercase Latin letters and the dollar sign ($). The latter is called a guard and has the code less than that of any of the letters. The guard appears only once in the string, in the last position. Then, for any integer k (1 ≤ kn-1, where k is a power of 2), we define the shaken form of S as the string T obtained as follows:

    1) For every cyclic shift of S write out the triple (PRK, POS, LAST), where PRK is the first k characters of the shifted string, POS is the position (counting from zero) of the first letter of S in the shifted string, and LAST is the last character of the shifted string.

    2) Sort the resulting triplets in ascending order , using the following rule to compare the triples: for any two triples C1 = (PRK1, POS1, LAST1) and C2 = (PRK2, POS2, LAST2) we will consider C1 < C2, if PRK1 is lexicographically less than PRK2 or , if they are equal, if POS1 < POS2.

    3) After sorting the triples, write out the values of LASTi in that order. This sequence of letters is the shaken form T.

    Let's consider an example for k = 2:

    The shaken form of a string usually has much simpler probabilistic structure than the original, which allows quite complicated information about S to be extracted from it using relatively simple algorithms. The researchers have accomplished that, but now they have decided it would be a waste to keep both the shaken T and the original S in the database. Using an automated theorem prover, they have learned that an efficient algorithm for extracting S from T must exist. However , they have been unable to derive the algorithm and have turned to you for help.

    Input

    The first line contains the value k and the second line the shaken string T.

    Output

    The first and only line of the output should contain the original string S, followed by a newline. The guard symbol $ should be left out.

    Sample Input

    2
    ipsms$pissii

    Sample Output

    mississippi

    Source

    样例输入

    2
    ipsms$pissii

    样例输出

    mississippi

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部