Given a number n and a pattern that follows like:
(1 to 26): a,b,c,….z
(27 to 52): aa,ab,ac,…az
(52 to 78): ba,bb,bc,…bz
. . . za,zb,zc,…zz
aaa,aab,aac,…aaz
aba,abb,abc,… . . . find the nth pattern
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 165 |
2 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
4 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Given a number n and a pattern that follows like:
(1 to 26): a,b,c,….z
(27 to 52): aa,ab,ac,…az
(52 to 78): ba,bb,bc,…bz
. . . za,zb,zc,…zz
aaa,aab,aac,…aaz
aba,abb,abc,… . . . find the nth pattern
Name |
---|
this is the link of problem , maybe it can helps you :) http://mirror.codeforces.com/gym/101372/attachments/download/5504/2017-russian-code-cup-rcc-17-3rd-qualification-round-en.pdf (problem A)
Actually I think this is what has been used in EXCEL...
One can find that the first 26 columns in EXCEL are denoted as A,B,...,Z while the next 26 ones are written as AA,AB,AC,....,AZ, and so on.
We can build a 26-ary tree to obtain an intuitive understanding of this problem. The root node is NULL, and it has 26 child nodes, denoted as A,B,...,Z. Next, node A has 26 child nodes A,B,....,Z, and node B has 26 child nodes A,B,...,Z, and node C has 26 child nodes A,B,...,Z, and so on. In a word, each node in the tree has exactly 26 child nodes, A,B,...,Z.
If we start from the root node and walk along the branches to some other node, all the nodes that have been visited just form the pattern A,B,...,Z,AA,AB,...,AZ,...
Moreover, if we assign index 0 to the root node, and increase the index from top to bottom and left to right, i.e., the child nodes of the root node are counted as 1,2,...,26, and so on, to calculate the n-th pattern is just to find out the route from root node to the node with index n.
For some node with index i, its child nodes have indices 26*i+1, 26*i+2,...,26*i+26. Thus, given node with index n, we can adopt this relationship to find out the route up to the root node, and output the letters that have been visited.
Similarly, given any pattern, like "AAC", we can also calculate its index.