''' mbinary ######################################################################### # File : winnerTree.py # Author: mbinary # Mail: zhuheqin1@gmail.com # Blog: https://mbinary.coding.me # Github: https://github.com/mbinary # Created Time: 2018-05-19 23:06 # Description: ######################################################################### ''' class winnerTree: '''if iself.s else 2*p+self.lowExt-self.n+1 def arrayToTree(self,i): return (i+self.offset)//2 if i<=self.lowExt else (i-self.lowExt+ self.n-1)//2 def win(self,a,b): return ab def initTree(self,p): if p>=self.n: delta = p%2 #!!! good job notice delta mark the lchild or rchlid return self.players[self.treeToArray(p//2)+delta] l = self.initTree(2*p) r = self.initTree(2*p+1) self.tree[p] = l if self.win(l,r) else r return self.tree[p] def winner(self): idx = 1 while 2*idx