程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> ACM-計算幾何之Quoit Design——hdu1007 zoj2107

ACM-計算幾何之Quoit Design——hdu1007 zoj2107

編輯:C++入門知識

Quoit Design

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

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 題目: hdu 1007 , zoj 2107

這道題,類型:求最近點對。 求平面 最近點對的方法,就是分治法。 先將點分成兩個區間,假設S1,S2,然後分別求S1內最近點對的點d1,S2內最近點對的點d2 再求S1與S2內最近點對 d=min(d1,d2) 但是,不能忘記,最近點對可能是 一個點在S1一個點在S2。 接下來就是比較精華的部分: 所求的點的位置,一定在於 mid-d,mid+d 之間。 然後,就在這個區間開始找點,並不斷更新d值,最後就可以得到d了。
這道題,最終要求半徑,所以還要除以2。
/**************************************
***************************************
*        Author:Tree                  *
*From :http://blog.csdn.net/lttree    *
* Title : Quoit Design                *
*Source: hdu 1007 zoj 2107            *
* Hint  : 計算幾何——最近點對         *
***************************************
**************************************/
#include 
#include 
#include 
using namespace std;
#define N 100001
struct Point
{
    double x,y;
}p[N];
int arr[N];
double Min(double a,double b)
{
    return a>1;
    double ans=Min(close_pair(l,mid),close_pair(mid+1,r));

    int i,j,cnt=0;
    // 如果 當前p[i]點 橫坐標位於 范圍(中點橫坐標-ans,中點橫坐標+ans)位置內,則記錄點的序號
    for(i=l; i<=r; ++i)
        if(  p[i].x>=p[mid].x-ans && p[i].x<=p[mid].x+ans  )
            arr[cnt++]=i;
    // 按照縱坐標由小到大 對於arr數組內點進行排序
    sort(arr,arr+cnt,cmp_y);
    for(i=0; i=ans) break;
            ans=Min(ans,dis(p[arr[i]],p[arr[j]]));
        }

    return ans;
}

int main()
{
    int i,n;
    while( scanf("%d",&n)!=EOF && n)
    {
        for(i=0;i


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved