2020牛客暑期多校训练营(第九场)
A. Groundhog and 2-Power Representation
题目描述
Groundhog took a math class. In this class, his math teacher said, any positive integer can be represented by the power of . For example, .
And powers are expressed in parentheses. That is, stands for . Therefore, can be expressed as .
Further more,for is expressed with , ,137 can be finally expressed as .
Another example, $ 2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)$.
Groundhog feels amazing and wants you to write a program to simulate the above content. You need to read in an expression that is a power of and calculate its value.
输入描述
Given a string, indicating the power representation.
输出描述
Output the original number.
示例1
输入
1 | 2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0) |
输出
1 | 1315 |
备注
The range of answers is ,and the length of the input data shall not exceed .
分析
题面的本质是定义了一个表达式,然后计算表达式的值;而众所周知, 的 函数可以直接输出表达式的值。
题中定义 为 ,而 中认为 为 。因此,只需要将表达式中的 替换为 ,就能用 函数计算表达式的值。
代码
1 | """*************************************************** |
I. Groundhog Looking Dowdy
题目描述
Today, ZLZX has a mysterious case, Orange lost his down jacket hanging in his dorm room. Under the expectations of everyone, detective Groundhog took his small spoon of the artifact and started the journey to solve the case.
After an in-depth investigation of the northernmost mysterious room on each floor, Groundhog discovered mysterious numbers. As long as the clues conveyed by these numbers are deciphered, he can reveal the truth of the matter. The deciphering method is, using these numbers to generate two positive integers without leading zeros, and minimizing the product of these two positive integers is the final clue.
Then Groundhog wants to know what the smallest product is?
As he continued to investigate in the room west of the new building, he gave you the question.
Concise meaning, given numbers between and , use them to make two positive integers without leading zeros to minimize the product.
输入描述
The first line of input is a single integer , the number of test cases.
For each set of data, each test case begins with a single integer , the count of numbers.
The next line are numbers.
输出描述
For each set of case, an integer is output, representing the smallest product.
示例1
输入
1 | 1 |
输出
1 | 122 |
示例2
输入
1 | 2 |
输出
1 | 1223 |
备注
, , .
There are at least two Numbers that are guaranteed not to be zero.
The Numbers range between .
分析
若不考虑前导零的限制,取 为 个数中的最小值, 为其余 个数组合起来的最小整数, 即为最小乘积。
考虑前导零后, 为 个数中的最小正整数, 为其余 个数组合起来的最小正整数。具体方法为:将 个数从小到大排序,取最小的正整数为 ;在剩余 个数中,取最小正整数为 的最高位,然后向 的低位补零,最后向 的低位从小到大不正整数。最后模拟个位数乘多位数的乘法输出 。
代码
1 | /****************************************************************** |