6. Electron Distribution.Проблем със задачата
-
6.Electron Distribution
You are a mad scientist and you have decided to play with electron distribution among atom's shells. You know that basic idea of electron distribution is that electrons should fill a shell until it's holding the maximum number of electrons.
You will receive a single integer – number of electrons. Your task is to fill shells until there are no more electrons left. The rules for electron distribution are as follows:
-
The maximum number of electrons in a shell can be 2n2, where n is the position of a shell (starting from 1). For example, the maximum number of electrons in the 3rd shield can be 2*32 = 18.
-
You should start filling the shells from the first one at the first position.
-
If the electrons are enough to completely fill the first shell, the left unoccupied electrons should fill the next shell and so on.
At the end, print a list with the filled shells.
Example
|
Input |
Output |
|
10 |
[2, 8] |
|
44 |
[2, 8, 18, 16] |
Получавам 40/10- излиза ми верен отговор на почти всякакви входове до 100.Нещо имам чувството,че не разбирам добре условието или не е обяснено както трябва.Една поредица от електрони върви 2,8,18,32,тук обаче максималното число което може да имаме в трета клетка е 18.Ако числото да кажем е 68 какъв трябва да е изхода 2,8,18,2,8,18,12 понеже остатъка е 12,както при 44 е остатък 16 или 2,8,18,40?
Понеже и 40 може да го разбия 2,8,18 и да създавам още клетки,та колко е максималния допустим брой клетки 3 ли и после слагаме остатъка какъвто е:
По-горния пример дето е 44 разбирам,че максималният допустим брой е три плюс клетката с остатък
Ето решението ми което дава 40/100
number=int(input())
new_list=[]
total=0
i=0
while 0<=number:
i+=1
shell=2*i**2
total+=shell
new_list.append(shell)
number-=shell
if number<18:
if number>0:
new_list.append(number)
break
if number==0:
new_list.append(number)
break
if i % 3==0:
i=0
print(new_list)
Благодаря за помоща,явно доста бях зациклил с тази задача:)