Initial commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
import math
|
||||
|
||||
def level1(fightingStyle1 , fightingStyle2):
|
||||
if fightingStyle1 =="R" and fightingStyle2 =="R":
|
||||
return "R"
|
||||
if fightingStyle1 =="R" and fightingStyle2 =="P":
|
||||
return "P"
|
||||
if fightingStyle1 =="R" and fightingStyle2 =="S":
|
||||
return "R"
|
||||
if fightingStyle1 =="P" and fightingStyle2 =="R":
|
||||
return "P"
|
||||
if fightingStyle1 =="P" and fightingStyle2 =="P":
|
||||
return "P"
|
||||
if fightingStyle1 =="P" and fightingStyle2 =="S":
|
||||
return "S"
|
||||
if fightingStyle1 =="S" and fightingStyle2 =="R":
|
||||
return "R"
|
||||
if fightingStyle1 =="S" and fightingStyle2 =="P":
|
||||
return "S"
|
||||
if fightingStyle1 =="S" and fightingStyle2 =="S":
|
||||
return "S"
|
||||
|
||||
def level2(tournament,k=2):
|
||||
# k in the number of rounds
|
||||
# tournament is the list of the tournament
|
||||
# tournament = ["R","P","S","R","P","S","R","P","S"]
|
||||
# return the participant after k rounds
|
||||
if len(tournament) == 1:
|
||||
return tournament
|
||||
else:
|
||||
newTournament = []
|
||||
for i in range(0,len(tournament),2):
|
||||
newTournament.append(level1(tournament[i],tournament[i+1]))
|
||||
return level2(newTournament,k-1)
|
||||
|
||||
def level3(tournament):
|
||||
array = tournament.split(" ")
|
||||
result = []
|
||||
R = int(array[0][0:-1])
|
||||
P = int(array[1][0:-1])
|
||||
S = int(array[2][0:-1])
|
||||
while R!=0 and P!=0:
|
||||
result.append("R")
|
||||
R = R-1
|
||||
if (R>1):
|
||||
result.append("R")
|
||||
R = R-1
|
||||
result.append("P")
|
||||
P = P-1
|
||||
if (R!=0):
|
||||
result.append("R")
|
||||
R = R-1
|
||||
while P!=0 :
|
||||
result.append("P")
|
||||
P = P-1
|
||||
while S!=0:
|
||||
result.append("S")
|
||||
S = S-1
|
||||
return result
|
||||
|
||||
# def level4(r, p, s, n, m):
|
||||
# llist = []
|
||||
# cap = m
|
||||
# start = 0
|
||||
# while r > 0 and p > 1 and r > p:
|
||||
# if r >= cap - 1:
|
||||
# for i in range(start, start + cap - 1):
|
||||
# llist.append("R")
|
||||
# r -= 1
|
||||
# llist.append("P")
|
||||
# p -= 1
|
||||
|
||||
# if r == 1:
|
||||
# llist.append("R")
|
||||
# r -= 1
|
||||
# llist.append("P")
|
||||
# p -= 1
|
||||
|
||||
# start += cap // 2
|
||||
# else:
|
||||
# cap = cap // 2
|
||||
|
||||
# if p == 1:
|
||||
# llist.append("P")
|
||||
# p -= 1
|
||||
# while r > 0:
|
||||
# llist.append("R")
|
||||
# r -= 1
|
||||
# else:
|
||||
# while r > 0:
|
||||
# llist.append("R")
|
||||
# r -= 1
|
||||
# llist.append("P")
|
||||
# p -= 1
|
||||
|
||||
# while s > 0:
|
||||
# llist.append("S")
|
||||
# s -= 1
|
||||
# while p > 0:
|
||||
# llist.append("P")
|
||||
# p -= 1
|
||||
|
||||
# string = ""
|
||||
# string = string.join(llist)
|
||||
# return string
|
||||
|
||||
|
||||
def main1():
|
||||
with open("level4_example.in","r") as f:
|
||||
with open("result.out","w") as f1:
|
||||
line = f.readline().split(" ")
|
||||
n = int(line[0])
|
||||
k = int(line[1])
|
||||
for i in range(n):
|
||||
tournament = f.readline()
|
||||
tournament = tournament[0:-1]
|
||||
result = "".join(level4(k,tournament=tournament))
|
||||
p = level2(result,k)
|
||||
assert (len(p) == 1)
|
||||
assert (p[0]=="S")
|
||||
print("ok\n")
|
||||
f1.write(result)
|
||||
f1.write("\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main1()
|
||||
Reference in New Issue
Block a user