ACM | Quoit Design

Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded. In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.

Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.

你曾经在操场上玩过掷环游戏吗?掷环是一种游戏,其中扁平的环被投向一些玩具,所有被环围绕的玩具都会被奖励。

在Cyberground领域中,每个玩具的位置都是固定的,环被精心设计,以便一次只能围绕一个玩具。另一方面,为了使游戏看起来更有吸引力,环被设计成具有最大半径。给定场地的配置,你需要找出这样一个环的半径。

假设所有的玩具都是平面上的点。如果一个点与环的中心之间的距离严格小于环的半径,则该点被环围绕。如果两个玩具位于同一点上,则环的半径被认为是0。

输入格式:

The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0. 输入包含多个测试用例。对于每个案例,第一行包含一个整数N(2 <= N <= 100,000),表示场地上玩具的总数。然后是N行,每行包含一个玩具的坐标(x, y)。输入以N = 0结束。

输出格式:

For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places. 对于每个测试用例,在一行中打印Cyberground管理员所需的环的半径,精确到小数点后2位。

输入样例:

2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0

输出样例:

0.71
0.00
0.75

代码示例1:

把sqrt放到最后减小运算量。但是1000000的数组用暴力还是太大了。 这个代码会超时。待我优化一番。

#include<stdio.h>
#include<math.h>
int main(){
    int n;
    scanf("%d",&n);
    double x[100000];
    double y[100000];
    while(n!=0){
        for(int i=0;i<n;i++){
            scanf("%lf%lf",x+i,y+i);
        }
        double x1,x2,y1,y2;
        double distance2=10000000.0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i!=j && distance2>(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])){
                    distance2=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
                    x1=x[i];
                    x2=x[j];
                    y1=y[i];
                    y2=y[j];
                }
            }
        }
        printf("%.2lf\n",sqrt(distance2)/2);
        scanf("%d",&n);
    }
    return 0;
}


ACM | Quoit Design
https://acm.nanyan.cc/posts/6220.html
作者
nanyan
发布于
2023年10月26日
许可协议