Created
August 11, 2016 17:51
-
-
Save shaunlgs/1b4f1f1660ee718348596a5be927ac9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
raw = input().split(" ") | |
decisions = [] | |
# decide first move | |
for i in range(1): | |
# gym no, contest no | |
if raw[i] == "0": | |
decisions.append("Rest") | |
# gym no, contest yes | |
elif raw[i] == "1": | |
decisions.append("Contest") | |
# gym yes, contest no | |
elif raw[i] == "2": | |
decisions.append("Gym") | |
# gym yes, contest yes | |
elif raw[i] == "3": | |
index = i | |
while True: | |
# still does not meet any no in the end | |
# example: yes yes, yes yes, yes yes, yes yes | |
if index == n - 1: | |
# choose any | |
decisions.append("Gym") | |
break | |
# gym no, contest no | |
if raw[index + 1] == "0": | |
# choose any | |
decisions.append("Gym") | |
break | |
# gym no, contest yes | |
elif raw[index + 1] == "1": | |
decisions.append("Gym") | |
break | |
# gym yes, contest no | |
elif raw[index + 1] == "2": | |
decisions.append("Contest") | |
break | |
# gym yes, contest yes | |
elif raw[index + 1] == "3": | |
index += 1 | |
for i in range(1, n): | |
# gym no, contest no | |
if raw[i] == "0": | |
decisions.append("Rest") | |
# gym no, contest yes | |
elif raw[i] == "1": | |
if decisions[i - 1] == "Rest": | |
decisions.append("Contest") | |
elif decisions[i - 1] == "Gym": | |
decisions.append("Contest") | |
elif decisions[i - 1] == "Contest": | |
decisions.append("Rest") | |
# gym yes, contest no | |
elif raw[i] == "2": | |
if decisions[i - 1] == "Rest": | |
decisions.append("Gym") | |
elif decisions[i - 1] == "Gym": | |
decisions.append("Rest") | |
elif decisions[i - 1] == "Contest": | |
decisions.append("Gym") | |
# gym yes, contest yes | |
elif raw[i] == "3": | |
if decisions[i - 1] == "Rest": | |
index = i | |
while True: | |
# still does not meet any no in the end | |
# example: yes yes, yes yes, yes yes, yes yes | |
if index == n - 1: | |
# choose any | |
decisions.append("Gym") | |
break | |
# gym no, contest no | |
if raw[index + 1] == "0": | |
# choose any | |
decisions.append("Gym") | |
break | |
# gym no, contest yes | |
elif raw[index + 1] == "1": | |
decisions.append("Gym") | |
break | |
# gym yes, contest no | |
elif raw[index + 1] == "2": | |
decisions.append("Contest") | |
break | |
# gym yes, contest yes | |
elif raw[index + 1] == "3": | |
index += 1 | |
elif decisions[i - 1] == "Gym": | |
decisions.append("Contest") | |
elif decisions[i - 1] == "Contest": | |
decisions.append("Gym") | |
restCount = 0 | |
for i in range(n): | |
if decisions[i] == "Rest": | |
restCount += 1 | |
print(restCount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment