NO.1
#encoding: UTF-8
'''
只想到用二分法查找
'''
import random
def FindMoney(aList):
if len(aList) == 2:
if aList[0] > aList[1]:
print aList[1]
else:
print aList[0]
else:
if sum(aList[len(aList)/2:]) > sum(aList[:len(aList)/2]):
FindMoney(aList[:len(aList)/2])
else:
FindMoney(aList[len(aList)/2:])
a = [1] *29 + [0]
a.sort(lambda a,b: random.randint(-1, 1)) #乱序
print a
FindMoney(a)
NO.2,详细解释请参照
http://blog.csdn.net/handsomekang/article/details/10089221#encoding: UTF-8
from collections import deque
import random
def Matchschedule(team):
c = team[1:]
c = deque(c)
for i in range(len(team) - 1):
c.appendleft(team[0])
for j in range(len(team)/2):
print c[j], "<----->", c[-1-j]
c.popleft()
c.append(c.popleft())
if __name__ == "__main__":
a = [i for i in range(1,33)]
Matchschedule(a)
追问谢谢