Blue Bridge Cup Python Group - Sorting

Blue Bridge Cup Python Group - Sorting

Topic description

This question is a fill-in-the-blank question. After calculating the result, use the output statement in the code to output the filled result.

Xiaolan recently learned some sorting algorithms, among which bubble sort impressed him a lot.

In bubble sort, only two adjacent elements can be swapped at a time.

Xiaolan found that if the characters in a string are sorted and only two adjacent characters are allowed to be swapped, the total number of swaps in bubble sort is the least among all possible sorting schemes.

For example, for the string lanlan ordering, only 11 swaps are required. For the string qiaoqiao sorting, a total of 44 swaps are required.

Xiaolan found a lot of strings and tried to sort them. He happened to come across a string that required 100,100 exchanges, but he forgot to write down this string and can't find it now.

Please help Xiaolan to find a string that contains only lowercase English letters and no repeated letters, and it takes exactly 100,100 exchanges to sort the characters of the string. If it is possible to find more than one, please tell Xiaolan the shortest one. If there are still more than one shortest, please tell Xiaolan the one with the smallest lexicographical order.

Running limit
Maximum running time: 1s
Maximum running memory: 128M

import os
import sys
'''
条件
 最短字符串 条件1
 最小字典序 条件2
 100次交换 条件3
完全逆序交换次数  jh = n*(n-1)/2
字符串长度为15时  jh=105
所以最短字符串长度就是15
条件1 已满足
最小字典序,从a开始,到o
条件2 已满足
完全逆序是 o~a
少交换5次。只需要把第6位的数,往前交换五次,排在首位
相应就是 只交换100次
'''
print("jonmlkihgfedcba")

Thank you for your support. Your one-click three-connection is the biggest driving force for Ganggang students!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324321330&siteId=291194637