【CSU-1828】解题报告(数论,康托展开逆展开)
原始题目
1828: Dictionary
- Time Limit: 2 Sec
- Memory Limit: 128 Mb
- Submitted: 202
- Solved: 146
Description
The isolated people of MacGuffin Island have a unique culture, and one of the most interesting things about them is their language. Their alphabet consists of the first 9 letters of the Roman alphabet (a, b, c, d, e, f, g, h, i). All of their words are exactly 9 letters long and use each of these 9 letters exactly once. They have a word for every possible permutation of these letters. In the library of their most sacred temple is a dictionary, and each word in their language has its own page. By coincidence they order their words exactly as they would be in ordered in English, so the word ‘abcdefghi’ is on the first page, and the word ‘ihgfedcba’ is on the last. The question is, given a list of random words from the MacGuffin language, can you say on which page of the MacGuffin dictionary each appears?
Input
The first line of the input file is a positive integer. This integer tells you how many words will follow. The upper limit for this number is 6000. Every subsequent line contains a single word from the MacGuffin language, so if the first number is 1000 there will be 1000 lines after it, each containing a single word.
Output
Each line of output will contain an integer. This integer should be the page number for the corresponding word.
Sample Input
4
abcdefgih
abcdefghi
abcdefgih
ihgfedcba
Sample Output
2
1
2
362880
Hint
Source
ACM-ICPC Asia Thailand National On-Site Programming Contest 2015
题目大意
输入一个由(a, b, c, d, e, f, g, h, i)各出现一次构成的八位字符串,求其在按字典序排列中的序号。
解题思路
看作1-8的排列,利用康托展开输出序号,模板题。
解题代码
1 |
|
收获与反思
- 感受模板的力量= =
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!