#P13208. [GCJ 2016 Finals] Gallery of Pillars

    ID: 15077 远端评测题 5000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2016数论莫比乌斯反演容斥原理Google Code Jam

[GCJ 2016 Finals] Gallery of Pillars

题目描述

Your friend Cody-Jamal is working on his new artistic installment called "Gallery of Pillars". The installment is to be exhibited in a square gallery of N\mathbf{N} by N\mathbf{N} meters. The gallery is divided into N2\mathbf{N}^{2} squares of 1 by 1 meter, forming an N\mathbf{N} by N\mathbf{N} matrix. The exact center of the southwest corner cell is called the viewpoint; a person viewing the artwork is supposed to stand there. Each other cell contains a cylindrical pillar. All pillars have two circular bases of radius R\mathbf{R}: one resting on the floor, in the center of its corresponding cell, and the other touching the gallery's ceiling. The observer will stand in the viewpoint, observe the N21\mathbf{N}^{2} - 1 pillars, and marvel.

Cody-Jamal is currently scouting venues trying to see how large he can make the value of N\mathbf{N}. Also, he has not decided which material the pillars will be made of; it could be concrete, or carbon nanotubes, so the radius R\mathbf{R} of the base of each pillar could vary from 1 micrometer to almost half a meter. Notice that a radius of half a meter would make neighboring pillars touch.

You, as a trained mathematician, quickly observe that there could be pillars impossible to see from the viewpoint. Cody-Jamal asks your help in determining, for different combinations of N\mathbf{N} and R\mathbf{R}, the number of visible pillars. Formally, a pillar is visible if and only if there is a straight line segment that runs from the center of the southwest corner cell (the viewpoint) to any point on the pillar's boundary, and does not touch or intersect any other pillar.

输入格式

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} lines follow. Each line describes a different test case with two integers N\mathbf{N} and R\mathbf{R}. N\mathbf{N} is the number of 1 meter square cells along either dimension of the gallery, and R\mathbf{R} is the radius of each pillar, in micrometers. Thus, R/106\mathbf{R} / 10^{6} is the radius of each pillar in meters.

输出格式

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 pillars in the installment that are visible from the viewpoint.

4
4 100000
4 300000
3 300000
100 499999
Case #1: 9
Case #2: 7
Case #3: 5
Case #4: 3

提示

Sample Explanation

The pictures below illustrate the first two samples (not to scale). In the center of the black circle is the observer. The other circles are pillars, with the visible ones in gray and the not visible ones in red. The blue dotted lines represent some of the unblocked lines of sight; the red dotted lines represent blocked lines of sight (that turn gray at the point at which they are first blocked).

Limits

  • 1T1001 \leqslant \mathbf{T} \leqslant 100.
  • 1R<106/21 \leqslant \mathbf{R} < 10^{6} / 2.

Small dataset (10 Pts, Test Set 1 - Visible)

  • 2N3002 \leqslant \mathbf{N} \leqslant 300.

Large dataset (30 Pts, Test Set 2 - Hidden)

  • 2N1092 \leqslant \mathbf{N} \leqslant 10^{9}.