(AtCoder) ABC308

前回:(AtCoder) ABC307 - gaaamiiのブログ

自分の得点状況。Aを21:10に、Bを21:20に提出してAC コンテスト成績証。レーティングは10から44になった

A,Bはできて、Cが通らず終了でした。 前回はA,Bでもバタバタしていたけど今回は落ち着いてすぐ出せたのは慣れてきたからかもしれません。

C問題

あら〜今回のCは簡単ですな〜と15分くらいで提出。しかしWA(不正解)に。浮動小数点数の誤差を考慮しないと通らないテストケースが含まれていたようです。Rubyを使っていたのでRationalクラスを使えば良いのでした。

n = gets.chomp.to_i people = n.times.map do |i| front_cnt, back_cnt = gets.chomp.split(" ").map(&:to_i) # このrateを front_cnt.to_f / (front_cnt + back_cnt).to_f にしていた... { num: i + 1, rate: Rational(front_cnt, front_cnt + back_cnt) } end people.sort! do |a, b| compared = b[:rate] <=> a[:rate] if compared.zero? a[:num] <=> b[:num] else compared end end nums = people.map { |person| person[:num] } puts nums.join(" ")