标签:style blog color os ar for sp div 问题
#encoding:utf-8 #!usr/bin/python import sys def winner(n,m): s = 0 for i in range(1,n+1): s = (s+m)%i print ‘The last winner is: ‘,s+1 def josephus(n,m): a = [] b = [] for i in range(n): a.append(i+1) print ‘The orignal sequence:‘ print a j = 0 i = m - 1 while (j < n): for k in range(len(a)): if i >=len(a): i = i - len(a) break b.append(a[i]) a.remove(a[i]) i += m-1 j += 1 print ‘Josephus sequence(‘,n,‘people,space num is:‘,m,‘):‘ print b if __name__ == "__main__": josephus(41,3) winner(41,3)
标签:style blog color os ar for sp div 问题
原文地址:http://www.cnblogs.com/iGISer/p/3994958.html