Ruby. My code was:bernds wrote:Which language were you using? Perhaps something turned out not quite as portable between systems as one would hope.
Code: Select all
tests = gets.to_i
1.upto(tests) do |t|
area = gets.to_i
side = [(area/3.0).ceil, 3].max
rect = side.times.map { [0,0,0] }
while true
best = 1.upto(side-2).min_by do |c|
(-1..1).map do |x|
(-1..1).map do |y|
rect[c+x][y]
end.sum
end.sum
end
puts [best+1, 2].join(' ')
STDOUT.flush
x, y = gets.chomp.split.map(&:to_i)
break if (x == 0 && y == 0)
return if (x == -1 && y == -1)
rect[x-1][y-1] = 1
end
end
The code simple creates a 3*X rectangle large enough that it covers sufficient area for the given test, then it keeps finding the 3x3 subrectangle with the most empty cells and outputs the middle cell thereof until the rectangle is filled.