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
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 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
Название |
---|
this is the link of problem , maybe it can helps you :) http://codeforces.me/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.