아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Pixelated Circle

메모리 제한1024 MB

요약
0 방향으로 반올림하는 규칙 아래 두 원 채우기 결과를 비교해 색이 다른 픽셀 수를 세는 문제입니다.
난이도

보통10점 중 7점

유형
기하, 수학, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

Typical computer images are matrices of pixels, with each pixel being a small square of a specific color. Drawing lines that are not perfectly parallel to the axes of the pixel matrix results in imperfections. Drawing circles is an extreme example where those imperfections arise.

Suppose we have a picture consisting of 2R+12\mathbf{R}+1 by 2R+12\mathbf{R}+1 pixels, and we number the rows and columns of pixels between −R-\mathbf{R} and R\mathbf{R}, such that the center pixel is at row 00 and column 00. Initially, all pixels are white. Then, a circle of radius R\mathbf{R} and centered in the picture can be drawn in black by the following pseudocode, where set_pixel_to_black(x, y) makes the pixel at row xx and column yy be colored black.

draw_circle_perimeter(R):
  for x between -R and R, inclusive {
    y = round(sqrt(R * R - x * x))   # round to nearest integer, breaking ties towards zero
    set_pixel_to_black(x, y)
    set_pixel_to_black(x, -y)
    set_pixel_to_black(y, x)
    set_pixel_to_black(-y, x)
  }

Notice that some pixels may be set to black more than once by the code, but the operation is idempotent (that is, calling set_pixel_to_black on a pixel that is already black changes nothing).

The following is pseudocode for a function to draw a filled circle (starting from an all-white picture).

draw_circle_filled(R):
  for x between -R and R, inclusive {
    for y between -R and R, inclusive {
      if round(sqrt(x * x + y * y)) ≤ R:
        set_pixel_to_black(x, y)
    }
  }

And finally, the following is pseudocode to incorrectly draw a filled circle:

draw_circle_filled_wrong(R):
  for r between 0 and R, inclusive {
    draw_circle_perimeter(r)
  }

Given R\mathbf{R}, calculate the number of pixels that would have different colors between a picture in which draw_circle_filled(R\mathbf{R}) is called and another one in which draw_circle_filled_wrong(R\mathbf{R}) is called.

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case is described in a single line containing a single integer R\mathbf{R}, the radius of the circle to draw.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the number of pixels that would have different colors between a picture in which draw_circle_filled(R\mathbf{R}) is called and another one in which draw_circle_filled_wrong(R\mathbf{R}) is called.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.

힌트

In Sample Case #1, 21 pixels are drawn in black by calling draw_circle_filled(2) (shown in the left picture). 17 pixels are drawn in black by calling draw_circle_filled_wrong(2) (shown in the right picture). Four pixels would have different colors between the two pictures: (−1,−1)(-1, -1), (−1,1)(-1, 1), (1,−1)(1, -1), and (1,1)(1, 1), where (x,y)(x, y) represents the pixel at row xx and column yy, with the rows and columns numbered as described in the statement.

In Sample Case #2, the following pictures are the images generated by calling draw_circle_filled(8) (left) and draw_circle_filled_wrong(8) (right).

예제1

  1. 예제 1

    입력
    3
    2
    8
    50
    
    예상 출력
    Case #1: 4
    Case #2: 24
    Case #3: 812