HDU 1007 平面最近点对(计算集几何)
2014-02-27 19:04
302 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1007
我的代码:
我的代码:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define size 100000 struct pint{double x, y;} jeo[size]; bool cmpx(const int &a, const int &b){return jeo[a].x < jeo[b].x;} bool cmpy(const int &a, const int &b){return jeo[a].y < jeo[b].y;} double dis(int &a, int &b) { return sqrt((jeo[a].x - jeo[b].x) * (jeo[a].x - jeo[b].x) + (jeo[a].y - jeo[b].y) * (jeo[a].y - jeo[b].y)); } int n, idx[size], idy[size]; double judge(int l, int r) { if (r - l == 1) return dis(idx[l], idx[r]); if (r - l == 2) return min(dis(idx[l], idx[l + 1]), min(dis(idx[l + 1], idx[l + 2]), dis(idx[l + 2], idx[l]))); int mid = (l + r) >> 1; double ans = min(judge(l, mid), judge(mid + 1, r)); int num = 0; for(int i = l; i <= r; i++) if (jeo[idx[i]].x >= jeo[idx[mid]].x - ans && jeo[idx[i]].x <= jeo[idx[mid]].x + ans) idy[num++] = idx[i]; sort(idy, idy + num, cmpy); for(int i = 0; i < num; i++) for(int j = i + 1; j < num; j++) { if (jeo[idy[j]].y - jeo[idy[i]].y >= ans) break; ans = min(ans, dis(idy[j], idy[i])); } return ans; } int main() { while(scanf("%d", &n) && n) { for(int i = 0; i < n && scanf("%lf%lf", &jeo[i].x, &jeo[i].y); i++) idx[i] = i; sort(idx, idx + n, cmpx); printf("%.2f\n", judge(0, n - 1) * 0.5); } return 0; }
相关文章推荐
- HDU 1007 Quoit Design(计算几何 平面最近点对)
- Hdu 1007 - Quoit Design//分治,最近点对,计算几何
- HDU 1589 Stars Couple(计算几何求二维平面的最近点对和最远点对)
- 计算几何 平面最近点对 nlogn分治算法 求平面中距离最近的两点
- HDU-1007 Quoit Design 平面最近点对
- hdu_round1-1007 吃巧克力(计算几何)
- [计算几何]平面最近点对
- hdu 1007 Quoit Design 平面最近点对
- HDU - 1007 - Quoit Design (分治解平面最近点对)
- hdu 1007(计算几何)
- 初学算法-分治法求平面上最近点对(Closest Pair)-HDU 1007
- 计算几何 平面最近点对 nlogn分治算法 求平面中距离最近的两点
- hdu 1007 平面最近点对 分治
- 平面上最近点对(计算几何,分治,KDtree)(AOJ 862)(待补)
- 计算几何模板——平面最近点对(附C++源代码) - [转载经典]
- hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形
- 【几何】HDU 1007 Quoit Design 最近点对
- hdu 1007_平面最近点对模板
- 【几何】HDU 1007 Quoit Design 最近点对
- hdu&nbsp;1007&nbsp;平面最近点对&nbsp;&nbsp;随机增量…