平分算法
21个筐,7个满,7个半,7个空,3人平分
代码:
1 #!/usr/bin/env python 2 # encoding: utf-8 3 """ 4 @author: 侠之大者kamil 5 @file: 平分问题.py 6 @time: 2016/4/20 15:23 7 for a in range(4): 8 for b in range(min(4,7 - a + 1,a + 1)): 9 c = 7 -a -b 10 if c >= 4 or c > b: 11 continue 12 ah = int((3.5 - a) / 0.5) 13 bh = int((3.5 - b) / 0.5) 14 ch = int((3.5 - c) / 0.5) 15 if ah + bh + ch == 7: 16 print("*" * 18) 17 print(a, ah, 7 - a - ah) 18 print(b, bh, 7 - b - bh) 19 print(c, ch, 7 - c - ch)
结果:
ssh://kamil@xzdz.hk:22/usr/bin/python3 -u /home/kamil/windows_python3/python3/quweibaidu/平分问题.py ****************** 3 1 3 2 3 2 2 3 2 ****************** 3 1 3 3 1 3 1 5 1 Process finished with exit code 0