QOJ.ac

QOJ

時間限制: 10 s - 15 s 記憶體限制: 1024 MB 總分: 21

#12486. 像素化圆

统计

典型的计算机图像是由像素组成的矩阵,每个像素都是特定颜色的小方块。绘制与像素矩阵坐标轴不完全平行的线条会导致瑕疵。绘制圆形是出现此类瑕疵的一个极端例子。

假设我们有一张由 $2R + 1$ 乘以 $2R + 1$ 个像素组成的图片,我们将像素的行和列编号为 $-R$ 到 $R$,使得中心像素位于第 $0$ 行第 $0$ 列。最初,所有像素都是白色的。然后,可以通过以下伪代码在图片中绘制一个半径为 $R$ 且以图片中心为圆心的黑色圆,其中 set_pixel_to_black(x, y) 将第 $x$ 行第 $y$ 列的像素涂成黑色。

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)
 }

注意,代码可能会多次将某些像素设置为黑色,但该操作是幂等的(即,对已经为黑色的像素调用 set_pixel_to_black 不会有任何改变)。

以下是绘制实心圆的函数伪代码(从全白图片开始)。

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)
 }
 }

最后,以下是错误绘制实心圆的伪代码:

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

给定 $R$,计算调用 draw_circle_filled(R) 得到的图片与调用 draw_circle_filled_wrong(R) 得到的图片之间颜色不同的像素数量。

输入格式

第一行输入包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例由单行组成,包含一个整数 $R$,即要绘制的圆的半径。

输出格式

对于每个测试用例,输出一行 Case #x: y,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是调用 draw_circle_filled(R) 得到的图片与调用 draw_circle_filled_wrong(R) 得到的图片之间颜色不同的像素数量。

数据范围

内存限制:1 GB。 $1 \le T \le 100$。

子任务

测试集 1(可见判决): 时间限制:10 秒。 $1 \le R \le 100$。

测试集 2(隐藏判决): 时间限制:15 秒。 $1 \le R \le 10^5$。

样例

输入 1

3
2
8
50

输出 1

Case #1: 4
Case #2: 24
Case #3: 812

说明 1

在样例 1 中,调用 draw_circle_filled(2) 会将 21 个像素涂成黑色(如左图所示)。调用 draw_circle_filled_wrong(2) 会将 17 个像素涂成黑色(如右图所示)。两张图片之间有 4 个像素颜色不同:$(-1, -1)$、$(-1, 1)$、$(1, -1)$ 和 $(1, 1)$,其中 $(x, y)$ 表示第 $x$ 行第 $y$ 列的像素,行和列的编号如题目描述中所述。

在样例 2 中,下图是调用 draw_circle_filled(8)(左)和 draw_circle_filled_wrong(8)(右)生成的图像。

Figure 1. draw_circle_filled(2)

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.