atcoder ABC308 C - Standingsの勉強

atcoder.jp

・参考:
コード自体の参考
Submission #43161216 - AtCoder Beginner Contest 308
decimalの参考
Decimal (十進浮動小数点数型)


・注意点:pythonでは小数点15桁までしか表示できずそのためWAしてしまう。decimalモジュールを使うとこれを回避できる。

・コード:

from decimal import Decimal,getcontext
getcontext().prec=100  #小数点100桁まで
n=int(input())

ans=[]

for i in range(n):
  a,b=map(Decimal, input().split())
  ans.append((a/(a+b),i+1))
  
from operator import itemgetter   #ソートのため
ans=sorted(ans,reverse=True,key=itemgetter(0))   #ansの0列目を比較して同じ値があれば、1列目が小さい順に並べる。
#ans.sort(reverse=True)
#print(ans)

for x,y in ans:
  print(y,end=" ")