zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    每日一水 POJ8道水题
    编译和使用 MySQL C++ Connector
    j2ee model1模型完成分页逻辑的实现 详解!
    DB查询分析器访问EXCEL时,要在表名前后加上中括弧或双引号
    指向结构体变量的指针
    EOSS V3.0 企业运营支撑系统(基于RBAC原理的权限管理)
    MybatisGen1.0 Mybatis JavaBean Mapper生成工具
    The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by
    资源-Android:Android
    软件-开发软件:Android Studio
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5693071.html
Copyright © 2011-2022 走看看