• Quoit Design


    Quoit Design

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 46340    Accepted Submission(s): 12084

    这题可以分治:

    首先按照x方向排序,然后分别对 两边求最短距离。

    然后按照y排序,统计距离分割点-d 和+d之间的点,算了,忘了。

    但是可以直接排序,然后枚举相邻三个点之间到距离。这三个点的组合总计三个距离,可以证明最短到距离一定存在于某个

    三元组里。

    Problem Description
    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.
     
    Input
    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.
     
    Output
    For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places. 
     
    Sample Input
    2 0 0 1 1 2 1 1 1 1 3 -1.5 0 0 0 0 1.5 0
     
    Sample Output
    0.71 0.00 0.75
     
    Author
    CHEN, Yue
     
    Source
     
    Recommend
    JGShining
     
    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    const int maxx=100005;
    struct Node{
        double x;
        double y;
    }node[maxx];
    bool cmp(Node a,Node b){
        if(a.x!=b.x) return a.x<b.x;
        return a.y<b.y;
    }
    double dis(Node a,Node b){
        double dx,dy;
        dx=a.x-b.x;
        dy=a.y-b.y;
        double ans=dx*dx+dy*dy;
        return sqrt(ans);
    }
    double min(double a,double b,double c){
    
        double tmp=0.0;
        tmp=(a<=b)?a:b;
        tmp= (tmp<=c)?tmp:c;
        //cout<<a<<"  "<<b<<" "<<c<<"  "<<tmp<<endl;
        return tmp;
    }
    int main(){
            
        int n;
        while(scanf("%d",&n)&&n!=0){
    
            for(int i=0;i<n;i++){
                scanf("%lf%lf",&node[i].x,&node[i].y);
            }
            sort(node,node+n,cmp);
            double ans=1000000.0;
            if(n==1){
                printf("0.00
    ");
                continue;
            }else if(n==2){
                printf("%.2lf
    ",dis(node[0],node[1])/2);
                continue;
            }
            double tmp;
            for(int i=1;i<n-1;i++){
                tmp=min(dis(node[i-1],node[i]),dis(node[i],node[i+1]),dis(node[i-1],node[i+1]));
                ans=min(ans,tmp);
            }
            ans=ans/2;
            printf("%.2lf
    ",ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    C++类构造函数初始化列表
    VC++检测硬件设备状态
    MFC中调用Windows API函数的方式
    DEBUG无法进入断点解决方法
    【转】c++数组初始化
    vc++实现控制USB设备启用与否
    3d图像坐标轴及css3属性的讲解
    Ajax的兼容及Ajax的缓存问题
    Ajax中最有名axios插件(只应用于Ajax)(post方法,官网写错了,应是字符串格式)
    文档碎片及xml讲解
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5693071.html
Copyright © 2020-2023  润新知