Archery Game
Archery Game
Problem:
In an archery game, a bow and arrow is used to aim at the center of the circular target. The points are awarded based on how close the arrow hits the center of the target. The points for a shoot is calculated by the formula (3 - DISTANCE FROM CENTER OF THE TARGET) * 100. The target has radius of 3 units and any arrow hitting outside of the target will result in 0 points. Given N records with archer's name and the arrow's landing coordinates print the leaderboard (sorted by the total points, with highest score first) rounded up to 2 decimal places. The archers name could be repeated as a single archer can shoot multiple times.
Boundary Condition:
1<= N <= 1000
Input Format:
First line contains N. Next N lines contain the archers name and arrow's landing coordinates separated by a space.
Output Format:
D lines containing the name of the archer and their total points scored separated by a space . D denotes the unique archers count.
Example Input/Output 1:
Input:
6
Ravi 1 1
Ravi 2 2
Ram 0.4 0.3
Divya 1.3 2.5
Divya 2.5 3.4
Ram 0.2 0.4
Output:
Ram 505.28
Ravi 175.74
Divya 18.22
Program:
n = int(input())
lb = []
pt = []
for i in range(n):
a,b,c = input().strip().split()
b,c = float(b), float(c)
dist = (b**2 + c**2)**(0.5)
pts = (3 - dist)*100
if a not in lb:
lb.append(a)
pt.append(0)
pos = lb.index(a)
if pts > 0:
pt[pos] += pts
while pt != []:
pos = pt.index(max(pt))
print(lb[pos], "%.2f"%pt[pos])
lb.pop(pos)
pt.pop(pos)
Comments
Post a Comment