21889_PowerHungryCows

2022-5-16 18:20| 发布者: Hocassian| 查看: 28| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505933640399-Problem List-采集的数据-后羿采集器.html

Pro.ID

21889

Title

Power Hungry Cows

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21889

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    You are to write a program to solve jigsaw puzzles. The input file will contain the dimension of the puzzle, the dimension of the pieces, and the actual pieces of the puzzle. The pieces will be made up of ASCII characters. You are to create an output file which consists of FJ's cows would like to be able to compute integer powers P (1 ≤ P ≤ 20,000) of numbers very quickly, but need your help. Because they're going to be computing powers of very large numbers, they can only keep around two work variables for intermediate results.

    The first of those work variables is initialized to the number (denoted x) for which they are calculating the power; the other is initialized to 1. The cows can both multiply and divide any pair of the work variables and store the result in any work variable, but all results are stored as integers.

    For example, if they want to compute x31, one way to perform the calculation is:

                                                  WV1  WV2
                                          Start:   x    1
       Multiply first by first, store in second:   x   x2
                      Multiply second by second:   x   x4
                      Multiply second by second:   x   x8
                      Multiply second by second:   x   x16
                      Multiply second by second:   x   x32
                         Divide second by first:   x   x31

    Thus, x31 can computed in six operations. Given the power to be computed and the the number of work variables, find the minimum number of operations to calculate the power.

    输入

    A single line with one integer: P.

    输出

    Description

    You are to write a program to solve jigsaw puzzles. The input file will contain the dimension of the puzzle, the dimension of the pieces, and the actual pieces of the puzzle. The pieces will be made up of ASCII characters. You are to create an output file which consists of FJ's cows would like to be able to compute integer powers P (1 ≤ P ≤ 20,000) of numbers very quickly, but need your help. Because they're going to be computing powers of very large numbers, they can only keep around two work variables for intermediate results.

    The first of those work variables is initialized to the number (denoted x) for which they are calculating the power; the other is initialized to 1. The cows can both multiply and divide any pair of the work variables and store the result in any work variable, but all results are stored as integers.

    For example, if they want to compute x31, one way to perform the calculation is:

                                                  WV1  WV2
                                          Start:   x    1
       Multiply first by first, store in second:   x   x2
                      Multiply second by second:   x   x4
                      Multiply second by second:   x   x8
                      Multiply second by second:   x   x16
                      Multiply second by second:   x   x32
                         Divide second by first:   x   x31

    Thus, x31 can computed in six operations. Given the power to be computed and the the number of work variables, find the minimum number of operations to calculate the power.

    Input

    A single line with one integer: P.

    Output

    A single line with a single integer that is the minimum number of operations it requires to compute the power.

    Sample Input

    31

    Sample Output

    6

    Source

    样例输入

    31

    样例输出

    6

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部