Problem A : Quoit Design

#include<iostream>

#include<cstdio>

#include<vector>

#include<cmath>

#include<algorithm>

using namespace std;

struct point{

double x,y;

point(double xx = 0,double yy = 0){

x = xx;

y = yy;

}

void input(){

scanf("%lf%lf",&x,&y);

}

};

bool cmpx(point a,point b){

return a.x<b.x;

}

bool cmpy(point a,point b){

return a.y<b.y;

}

double dist(point a,point b){

return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

}

vector<point> v;

double dfs(int l,int r){

vector<point> tem;

if(l+1==r)return dist(v[l],v[r]);

int mid = (l+r)>>1;

double d1 = dfs(l,mid);

double d2 = dfs(mid,r);

double d = min(d1,d2);

for(int i=0;;i++){

if(mid-i>=l&&abs(v[mid-i].x-v[mid].x)<=d){

tem.push_back(v[mid-i]);

}else{

break;

}

}

for(int i=1;;i++){

if(mid+i<=r&&abs(v[mid+i].x-v[mid].x)<=d){

tem.push_back(v[mid+i]);

}else{

break;

}

}

sort(tem.begin(),tem.end(),cmpy);

double minn = 1e10;

for(int i= 0;i<tem.size();i++){

for(int j=i+1;j<tem.size();j++){

if(tem[j].y-tem[i].y<=minn){

minn = min(minn,dist(tem[i],tem[j]));

}else{

break;

}

}

}

return min(d,minn);

}

int main(){

int N;

while(scanf("%d",&N)!=EOF&&N){

v.clear();

for(int i=0;i<N;i++){

point tem;tem.input();

v.push_back(tem);

}

sort(v.begin(),v.end(),cmpx);

printf("%.2lf\n",dfs(0,v.size()-1)/2);

}

}

时间: 2024-12-29 12:41:23

Problem A : Quoit Design的相关文章

HDU1007 Quoit Design 【分治】

Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 30505    Accepted Submission(s): 8017 Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat

HDU 1007 Quoit Design

Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 130 Accepted Submission(s): 72   Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings a

HDU 1007 Quoit Design (分治)

Quoit Design 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 ri

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之间的点,算了,忘了. 但是可以直接排序,然后枚举相邻三个点之间到距离.这三个点

ZOJ - 2107 Quoit Design [分治]

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17751 题目描述:求最近点对 题目分析:分治,(nlogn): 为什么,第二轮按排序:http://noalgo.info/793.html 代码: //problem: zoj 2107 Quoit Design //author: ACsorry //result: Yes #include<iostream> #include<cstdio>

Quoit Design(hdu1007)最近点对问题。模版哦!

Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30919 Accepted Submission(s): 8120 Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings

hdu 1007 Quoit Design 分治求最近点对

Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29344    Accepted Submission(s): 7688 Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat

分治 [HDU 1007] Quoit Design

Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 33577    Accepted Submission(s): 8800 Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat

Quoit Design(最近点对+分治)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 42865    Accepted Submission(s): 11128 Problem Description Have you ever played