Skip to content

Instantly share code, notes, and snippets.

@vestige
Created October 22, 2012 13:13
Show Gist options
  • Select an option

  • Save vestige/3931454 to your computer and use it in GitHub Desktop.

Select an option

Save vestige/3931454 to your computer and use it in GitHub Desktop.
acm1
# http://icpc2010.honiden.nii.ac.jp/domestic-contest/problems#section_A
# 1
# 5
# 0 0
# 0 1
# 0 2
# 0 3
class Kaku
def initialize()
@x_min = 0
@x_max = 0
@y_min = 0
@y_max = 0
# @inputs = {1 => nil,
# 5 => [[0, 0], [0, 1], [0, 2], [0, 3]],
# 12 => [[0, 0], [1, 0], [2, 0], [3, 1], [4, 1], [5, 1], [6, 2], [7, 2], [8, 2], [9, 3]
# }
@inputs = {12 => [[0, 0], [1, 0], [2, 0], [3, 1], [4, 1], [5, 1], [6, 2], [7, 2], [8, 2], [9, 3]]}
@points = {0 => [0, 0]}
@count = 0
end
def set_point(target, direction)
tmp = @points[target]
if tmp == nil
return false
end
@count += 1
if (direction == 0)
@points.store(@count, [tmp[0] - 1, tmp[1]])
elsif (direction == 1)
@points.store(@count, [tmp[0], tmp[1] - 1])
elsif (direction == 2)
@points.store(@count, [tmp[0] + 1, tmp[1]])
elsif (direction == 3)
@points.store(@count, [tmp[0], tmp[1] + 1])
else
return;
end
end
def store_point()
@inputs.each do |key, i|
if (i.nil?)
p 1
next
end
i.each do |data|
target = data[0]
direction = data[1]
set_point(target, direction)
end
end
@points
end
def boxsize()
init = 0
@points.each do |key, i|
if init == 0
@x_min = i[0]
@x_max = i[0]
@y_min = i[1]
@y_max = i[1]
init = 1
next
end
if (i[0] < @x_min)
@x_min = i[0]
elsif (i[0] > @x_max)
@x_max = i[0]
end
if (i[1] < @y_min)
@y_min = i[1]
elsif (i[1] > @y_max)
@y_max = i[1]
end
end
return [(@x_max - @x_min).abs + 1, (@y_max - @y_min).abs + 1]
end
end
k = Kaku.new
p k.store_point()
p k.boxsize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment