Fully cover a rectangle with minimum amount of fixed radius circles

后端 未结 5 1543
自闭症患者
自闭症患者 2021-01-31 04:07

I\'ve had this problem for a few years. It was on an informatics contest in my town a while back. I failed to solve it, and my teacher failed to solve it. I haven\'t met anyone

5条回答
  •  悲&欢浪女
    2021-01-31 04:23

    The hexagon is better than the diamond. Consider the percent area of the unit circle covered by each:

    #!/usr/bin/env ruby
    
    include Math
    
    def diamond
      # The distance from the center to a corner is the radius.
      # On a unit circle, that is 1.
      radius = 1
    
      # The edge of the nested diamond is the hypotenuse of a
      # right triangle whose legs are both radii.
      edge = sqrt(radius ** 2 + radius ** 2)
    
      # The area of the diamond is the square of the edge
      edge ** 2
    end
    
    def hexagon
      # The hexagon is composed of 6 equilateral triangles.
      # Since the inner edges go from the center to a hexagon
      # corner, their length is the radius (1).
      radius = 1
    
      # The base and height of an equilateral triangle whose
      # edge is 'radius'.
      base = radius
      height = sin(PI / 3) * radius
    
      # The area of said triangle
      triangle_area = 0.5 * base * height
    
      # The area of the hexagon is 6 such triangles
      triangle_area * 6
    end
    
    def circle
      radius = 1
      PI * radius ** 2
    end
    
    puts "diamond == #{sprintf "%2.2f", (100 * diamond / circle)}%"
    puts "hexagon == #{sprintf "%2.2f", (100 * hexagon / circle)}%"
    

    And

    $ ./geometrons.rb 
    diamond == 63.66%
    hexagon == 82.70%
    

    Further, regular hexagons are highest-vertex polygon that form a regular tessellation of the plane.

提交回复
热议问题