2019-02-01から1ヶ月間の記事一覧

AOJ(問題集)18

AIZU ONLINE JUDGE: Programming Challenge 0170 Lunch until (n = $<.gets.to_i).zero? data = n.times.map {$<.gets.split}.map {|a, *b| [a] + b.map(&:to_i)} selected = [] all = [*0...n] solve = ->(left, order) { return if data[order.last][2] < …

AOJ(問題集)17

AIZU ONLINE JUDGE: Programming Challenge 0160 Delivery Fee table = [[60, 2, 600], [80, 5, 800], [100, 10, 1000], [120, 15, 1200], [140, 20, 1400], [160, 25, 1600]] until (n = $<.gets.to_i).zero? result = n.times.map {$<.gets.split.map(&:to…

AOJ(問題集)16

AIZU ONLINE JUDGE: Programming Challenge 0150 Twin Prime N = 10007 sieve = [*0..N] 2.upto(Math.sqrt(N).to_i) do |i| next if sieve[i].zero? 2.upto(N / i) {|j| sieve[i * j] = 0} end sieve = sieve[2..-1].reject {|x| x.zero?} until (n = $<.get…