-
Notifications
You must be signed in to change notification settings - Fork 17
/
dota2-senate.py
76 lines (62 loc) · 2.12 KB
/
dota2-senate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from collections import deque
class Radiant:
name = "Radiant"
mark = "R"
class Dire:
name = "Dire"
mark = "D"
class Solution:
def predictPartyVictory(self, senate: str) -> str:
queue = deque(senate)
radiant_banned, dire_banned = 0, 0
radiant, dire = senate.count(Radiant.mark), senate.count(Dire.mark)
radiant_bans, dire_bans = 0, 0
last = senate[0]
while queue and radiant != radiant_banned and dire != dire_banned:
left = queue.popleft()
if left == Radiant.mark:
if radiant_banned > 0:
radiant_banned -= 1
radiant_bans += 1
else:
dire_banned += 1
queue.append(left)
last = left
else:
if dire_banned > 0:
dire_banned -= 1
dire_bans += 1
else:
radiant_banned += 1
queue.append(left)
last = left
return Radiant.name if last == Radiant.mark else Dire.name
def predictPartyVictory1(self, senate: str) -> str:
radiant_banned, dire_banned = 0, 0
radiant_bans, dire_bans = 0, 0
radiant, dire = senate.count(Radiant.mark), senate.count(Dire.mark)
banned = 0
pos = 0
while radiant != radiant_banned and dire != dire_banned:
pos = pos % len(senate)
senator = senate[pos]
if banned & 1 << pos:
pass
elif senator == Radiant.mark:
if radiant_bans > 0:
radiant_bans -= 1
radiant_banned += 1
banned |= 1 << pos
else:
dire_bans += 1
else:
if dire_bans > 0:
dire_bans -= 1
dire_banned += 1
banned |= 1 << pos
else:
radiant_bans += 1
pos += 1
if dire == dire_banned:
return Radiant.name
return Dire.name