Ch round #57-story of the OI class Caesar Password

Source: Internet
Author: User
Tags ord

An interesting question

In the test room, hash the code into an integer, multiply the value of the last asicc Code * 1 by * 10, get an integer, and then rank nlogn in disorder using the equality and uniqueness.

The proof is as follows:

For plaintext ABCDE

Ciphertext bcdef

There are (a-B) * 10000 + (B-c) * 1000 + (c-d) * 100 + (D-f) * 10 + (e-f) * 1 = a constant

We can pre-process this constant. For any f [a, B], A, and B belong to lowercase letters, we can pre-process the value.

Okay, this is the test room.

Sort and maintain the labels in sequence after preprocessing, and then pass O (n) over again. It's silly.

Ch round #57-story of the OI class

However, I finally thought about it again, but I still can directly hash it. After hash is used, it will be dedback ..

    

Const maxn = 600001; maxm = 26; maxlen = 5; var N, T, I, J: longint; A, B: array [0 .. maxn] of longint; F: array [0 .. maxm, 0 .. maxm] of longint; s: string; begin readln (n); for I: = 1 to maxm do for J: = 1 to maxm do if j> = I then f [I, j]: = J-I else f [I, j]: = 26-i + J; // obtain the value of hash for I: = 1 to n do begin readln (s); T: = 0; for J: = 1 to maxlen-1 do t: = T * 26 + F [ord (s [J])-ord ('A') + 1] [ord (s [J + 1]) -ord ('A') + 1]; A [T]: = I; B [T]: = ord (s [1]); // maintain the end label; for I: = 1 to n do begin readln (s); T: = 0; for J: = 1 to maxlen-1 do t: = T * 26 + F [ord (s [J])-ord ('A') + 1] [ord (s [J + 1]) -ord ('A') + 1]; writeln (A [T], '', F [ord (s [1])-ord ('A ') + 1] [ord (B [T])-ord ('A') + 1]); end.

 

Ch round #57-story of the OI class Caesar Password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.