After receiving n, we distribute n balls that are indistinguishable to three abc students, and c should not have fewer balls than b. All branches that can be distributed under these conditions are calculated using overlapping iterations.

```
n=int(input())
a=0
b=0
c=0
for i in range(1,n+1):
if b > c:
break
```

That's all I know. I wrote the code above, so it might be wrong, but I want to open it because I'm curious about how to solve it.

python

2022-09-20 14:42

We can find a natural solution (a, b, c) that satisfies these two conditions: a+b+c = n, b <= c.

a, b, c all `0...We'll have a value between n`

, so we'll spin a triple loop to pick out (0, 0, 0) to (n, n, n) that meets the above two conditions.

To reduce the number of loops, turn a double loop, and if the last one is c = n-a-b, the first condition is automatically satisfied, and only the second condition is examined.

2022-09-20 14:42

Popular Tags

Popular Questions

10 ipynb code content search tool recommendation

9 How do I add index rows in Python beginner Pandas?

11 I have a question about the pointer! *z = ~(hap & 0xFF); What does ~ mean in?

10 Find the intersection of two lists

11 I'd like to specify a specific order when selecting Python characters randomly, is it possible?

© 2022 pinfo. All rights reserved.