[Python training camp] Python daily practice -- day 5: stress calculation

πŸ“’πŸ“’πŸ“’πŸ“£πŸ“£πŸ“£
🌻🌻🌻 Hello, everyone. My name is Dream. I'm an interesting Python blogger. Please take care of me 😜😜😜
πŸ…πŸ…πŸ… CSDN is a high-quality creator in Python field and is a sophomore. Welcome to find me for cooperative learning (VX wants to enter the learning exchange group or learning materials at the end of the article. Welcome + + +)
πŸ’• Introduction note: this paradise is never short of genius, and hard work is your final admission ticket! πŸš€πŸš€πŸš€
πŸ’“ Finally, may we all shine where we can't see and make progress together 🍺🍺🍺
πŸ‰πŸ‰πŸ‰ "Ten thousand times sad, there will still be Dream, I have been waiting for you in the warmest place", singing is me! Ha ha ha~ 🌈🌈🌈
🌟🌟🌟✨✨✨

[Python training camp] is a topic brushing Carnival party for Python language learning! If you don't grasp the basic knowledge firmly, you are welcome to refer to this set of courses: Python open class It's best to use it together. If you like it, hurry up and subscribe! πŸ‹πŸ‹πŸ‹ If you don't have self-control or motivation to learn and communicate together, you are welcome to send a private letter or add my VX at the end of the text. I will pull you into the learning and communication group. We will communicate and study together and punch in the group

Title Description

Title Description
This question is a blank filling question. You only need to calculate the result and use the output statement in the code to output the filled result.
A batch of precious metal raw materials are neatly stacked in the high-tech laboratory of Planet X.
The shape and size of each metal raw material are exactly the same, but the weight is different. Metal materials are strictly stacked into pyramids.

                             7 
                            5 8 
                           7 8 8 
                          9 2 7 2 
                         8 1 4 9 1 
                        8 1 8 8 4 1 
                       7 9 6 1 4 5 4 
                      5 6 5 5 6 9 5 6 
                     5 5 4 7 9 3 5 5 1 
                    7 5 7 9 7 4 7 3 3 1 
                   4 6 4 5 5 8 8 3 2 4 3 
                  1 1 3 3 1 6 6 5 5 4 4 2 
                 9 9 9 2 1 9 1 9 2 9 5 7 9 
                4 3 3 7 7 9 3 6 1 3 8 8 3 7 
               3 6 8 1 5 3 9 5 8 3 8 1 8 3 3 
              8 3 2 3 3 5 5 8 5 4 2 8 6 7 6 9 
             8 1 8 1 8 4 6 2 2 1 7 9 4 2 3 3 4 
            2 8 4 2 2 9 9 2 8 3 4 9 6 3 9 4 6 9 
           7 9 7 4 9 7 6 6 2 8 9 4 1 8 1 7 2 1 6 
          9 2 8 6 4 2 7 9 5 4 1 2 5 1 7 3 9 8 3 3 
         5 2 1 6 7 9 3 2 8 9 5 5 6 6 6 2 1 8 7 9 9 
        6 7 1 8 8 7 5 3 6 5 4 7 3 4 6 7 8 1 3 2 7 4 
       2 2 6 3 5 3 4 9 2 4 5 7 6 6 3 2 7 2 4 8 5 5 4 
      7 4 4 5 8 3 3 8 1 8 6 3 2 1 6 2 6 4 6 3 8 2 9 6 
     1 2 4 1 3 3 5 3 4 9 6 3 8 6 5 9 1 5 3 2 6 8 8 5 3 
    2 2 7 9 3 3 2 8 6 9 8 4 4 9 5 8 2 6 3 4 8 4 9 3 8 8 
   7 7 7 9 7 5 2 7 9 2 5 1 9 2 6 5 3 9 3 5 7 3 5 4 2 8 9 
  7 7 6 6 8 7 5 5 8 2 4 7 7 4 7 2 6 9 2 1 8 2 9 8 5 7 3 6 
 5 9 4 5 5 7 5 5 6 3 5 3 9 5 8 9 5 4 1 2 6 1 4 3 5 3 2 4 1 
X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X 

The number represents the weight of the metal block (larger unit of measurement). XX on the bottom layer represents 3030 electronic scales with extremely high precision.
It is assumed that the weight of each raw material falls on the two metal blocks below very accurately. Finally, the weight of all metal blocks falls on the bottom electronic scale strictly and accurately.
The unit of measurement of the electronic scale is very small, so the number displayed is very large.
The staff found that the indication of the electronic scale with the smallest reading was 20864582312086458231
Please figure out: what is the indication of the electronic scale with the largest reading?

Operational limits
Maximum running time: 1s
Maximum operating memory: 128M

Problem solving ideas

  • Put the pyramid into the source code in the form of string
  • Create a double list, store all elements in different lists by column, and then store all lists as one element in a large list. list =[[int(i) for i in j.split()] for j in a.split('\n')]
  • Traverse each element in each small list and calculate the total weight of the elements in the next column in turn:
list[i+1][j] += list[i][j]/2
list[i+1][j+1] += list[i][j]/2
  • After traversal, the element in the last line is the total weight of each, and its value is calculated by min () and max () functions.

  • num1 = min(list[-1]) num2 = max(list[-1])

  • Finally, convert the output to the result (2086458231/num1)*num2, but the result with division must contain decimal. At this time, it can be forcibly changed into an integer through int, which is relatively simple. You can also use the format string method for output, but only if you need to change the result to float floating point type

Source sharing

# Ten thousand times sad, there will still be Dream, I have been waiting for you in the warmest place!
# @Time    : 2022/1/21 18:14
# @Author: it's Dream!
# @File: bearing calculation py
a='''                        7 
                            5 8 
                           7 8 8 
                          9 2 7 2 
                         8 1 4 9 1 
                        8 1 8 8 4 1 
                       7 9 6 1 4 5 4 
                      5 6 5 5 6 9 5 6 
                     5 5 4 7 9 3 5 5 1 
                    7 5 7 9 7 4 7 3 3 1 
                   4 6 4 5 5 8 8 3 2 4 3 
                  1 1 3 3 1 6 6 5 5 4 4 2 
                 9 9 9 2 1 9 1 9 2 9 5 7 9 
                4 3 3 7 7 9 3 6 1 3 8 8 3 7 
               3 6 8 1 5 3 9 5 8 3 8 1 8 3 3 
              8 3 2 3 3 5 5 8 5 4 2 8 6 7 6 9 
             8 1 8 1 8 4 6 2 2 1 7 9 4 2 3 3 4 
            2 8 4 2 2 9 9 2 8 3 4 9 6 3 9 4 6 9 
           7 9 7 4 9 7 6 6 2 8 9 4 1 8 1 7 2 1 6 
          9 2 8 6 4 2 7 9 5 4 1 2 5 1 7 3 9 8 3 3 
         5 2 1 6 7 9 3 2 8 9 5 5 6 6 6 2 1 8 7 9 9 
        6 7 1 8 8 7 5 3 6 5 4 7 3 4 6 7 8 1 3 2 7 4 
       2 2 6 3 5 3 4 9 2 4 5 7 6 6 3 2 7 2 4 8 5 5 4 
      7 4 4 5 8 3 3 8 1 8 6 3 2 1 6 2 6 4 6 3 8 2 9 6 
     1 2 4 1 3 3 5 3 4 9 6 3 8 6 5 9 1 5 3 2 6 8 8 5 3 
    2 2 7 9 3 3 2 8 6 9 8 4 4 9 5 8 2 6 3 4 8 4 9 3 8 8 
   7 7 7 9 7 5 2 7 9 2 5 1 9 2 6 5 3 9 3 5 7 3 5 4 2 8 9 
  7 7 6 6 8 7 5 5 8 2 4 7 7 4 7 2 6 9 2 1 8 2 9 8 5 7 3 6 
 5 9 4 5 5 7 5 5 6 3 5 3 9 5 8 9 5 4 1 2 6 1 4 3 5 3 2 4 1 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '''
list =[[int(i) for i in j.split()] for j in a.split('\n')]
for i in range(len(list[-1])-1):
    for j in range(len(list[i])):
        list[i+1][j] += list[i][j]/2
        list[i+1][j+1] += list[i][j]/2
num1 = min(list[-1])
num2 = max(list[-1])
# print('%.0f'%float((2086458231/num1)*num2))
print(int((2086458231/num1)*num2))

***

1. Method of creating double list: list =[[int(i) for i in j.split()] for j in a.split('\n')]
2. Format string method: '%. 0f'%float((2086458231/num1)*num2), which must be converted to floating point number type first.

πŸ… Today is my fifth day in Python training camp. I hope to see the best of you every day πŸ…

πŸ† Previous articles - good articles recommended πŸ†

πŸ₯‡ [Python open class] zero foundation playing with Python basics -- Section 1: Python's self introduction
πŸ† [Python training camp] Python daily practice -- day 1: shopping list
πŸ† [Python training camp] Python daily practice -- day 2: House plate making
πŸ† [Python training camp] Python daily practice -- day 3: Crop hybridization
πŸ† [Python training camp] Python daily practice -- day 4: arithmetic prime sequence
🌲🌲🌲 Well, that's all I want to share with you today
❀️❀️❀️ If you like it, don't be stingy with your one button three connections~

Keywords: Python Back-end

Added by dwfait on Sun, 23 Jan 2022 01:16:22 +0200