Skip to content

Instantly share code, notes, and snippets.

@track8
Created October 23, 2012 03:46
Show Gist options
  • Save track8/3936503 to your computer and use it in GitHub Desktop.
Save track8/3936503 to your computer and use it in GitHub Desktop.
ACM
#http://icpc2010.honiden.nii.ac.jp/domestic-contest/problems#section_A
class Kaku
def initialize(paterns)
@paterns = paterns
end
def ans
return "1 1" if @paterns.empty?
coordinates = @paterns.inject([[0, 0]]) do |c, p|
i = c[p[0]]
if (p[1] == 0)
c << [i[0] - 1, i[1]]
elsif (p[1] == 1)
c << [i[0], i[1] - 1]
elsif(p[1] == 2)
c << [i[0] + 1, i[1]]
elsif(p[1] == 3)
c << [i[0], i[1] + 1]
end
end
x_vals = coordinates.map {|c| c[0]}
y_vals = coordinates.map {|c| c[1]}
return "#{(x_vals.max - x_vals.min).abs + 1} #{(y_vals.max - y_vals.min).abs + 1}"
end
end
@kaku_list = []
File.open("./acm_icpc_A_sample.txt") do |f|
paterns = nil
f.each_line do |l|
next paterns << l.split(" ").map{ |i| i.to_i } if (l.chomp.index(" "))
@kaku_list << Kaku.new(paterns) if paterns
paterns =[]
end
end
@kaku_list.each { |k| puts k.ans }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment