HDOJ 1007 Quoit Design
来源:互联网 发布:如何给单片机烧录程序 编辑:程序博客网 时间:2024/05/29 15:12
题意:有若干组数据,每组数据第一行为n,后面有n行,每行有两个数据,代表一个点的坐标x,y。求这些点之间最近两点的距离的一半,结果保留两位小数。
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007
思路:分治,将所有点分成两部分,有些特殊情况,一点在左区域,另一点在右区域,在已知的最短距离一半的范围内查找是否存在更短的点对(参考:http://www.cnblogs.com/AdaByron/archive/2011/10/07/2200966.html)。
注意点:cin关闭流同步也会超时。用scanf能过。
以下为AC代码:
Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor129281222015-02-10 15:08:47Accepted10071216MS4340K2265 BG++luminous11#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <vector>#include <deque>#include <list>#include <cctype>#include <algorithm>#include <climits>#include <queue>#include <stack>#include <cmath>#include <map>#include <set>#include <iomanip>#include <cstdlib>#include <ctime>#define ll long long#define ull unsigned long long#define all(x) (x).begin(), (x).end()#define clr(a, v) memset( a , v , sizeof(a) )#define pb push_back#define mp make_pair#define read(f) freopen(f, "r", stdin)#define write(f) freopen(f, "w", stdout)using namespace std;//const double pi = acos(-1);const double eps = 1e-10;//const int dir[[4][2] = { 1,0, -1,0, 0,1, 0,-1 };const int maxn = 100010;const double inf = 1e+20;struct point{ double x, y;};point p[maxn], tmpt[maxn];inline double dist ( point a, point b ){ return sqrt ( ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) );}bool cmpxy ( point a, point b ){ if ( a.x != b.x ) return a.x < b.x; else return a.y < b.y;}bool cmpy ( point a, point b ){ return a.y < b.y;}double closest_pair ( int l, int r ){ double d = inf; if ( l == r )return d; if ( l + 1 == r )return dist( p[l], p[r] ); int mid = ( l + r ) >> 1; double d1 = closest_pair( l, mid ); double d2 = closest_pair( mid + 1, r ); d = min ( d1, d2 ); int k = 0; for ( int i = l; i <= r; i ++ ){ if ( fabs( p[mid].x - p[i].x ) <= d ){ tmpt[k++] = p[i]; } } sort ( tmpt, tmpt + k, cmpy ); for ( int i = 0; i < k; i ++ ){ for ( int j = i +1; j < k && tmpt[j].y - tmpt[i].y < d; j ++ ){ d = min ( d, dist ( tmpt[i], tmpt[j] ) ); } } return d;}int main(){ ios::sync_with_stdio( false ); int n; while ( scanf ( "%d", &n ) && n ){ //while ( cin >> n && n ){ for ( int i = 0; i < n; i ++ ){ scanf ( "%lf%lf", &p[i].x, &p[i].y ); //cin >> p[i].x >> p[i].y; } sort ( p, p + n, cmpxy ); printf ( "%0.2f\n", closest_pair( 0, n - 1 ) / 2 ); //cout << fixed << setprecision(2) << closest_pair( 0, n - 1 ) / 2 << endl; } return 0;}
0 0
- HDOJ 1007 Quoit Design
- HDOJ 1007 Quoit Design
- [最近点对]HDOJ 1007 Quoit Design
- HDOJ 1007 Quoit Design(分治)
- HDOJ 1007 Quoit Design 最近点对
- hdoj Quoit Design 1007 (二分&递归)
- HDOJ-1007 Quoit Design(最接近点问题)
- hdoj 1007 Quoit Design(分治法)
- 【分治】Quoit Design (HDOJ-1007最近点问题)
- hdu/hdoj 1007 Quoit Design (最近点对问题)
- HDOJ 1007 Quoit Design(最近点对)
- HDOJ 1007 Quoit Design (最近点对+分治)
- 1007:Quoit Design
- hdu 1007 Quoit Design
- hdu 1007 Quoit Design
- hdu 1007 Quoit Design
- HDU-1007 Quoit Design
- hdu 1007 Quoit Design
- JS实现是一个文本框(值为参数)输入另一个显示(查询结果)
- JAVA MD5算法
- Matlab播放音频文件(音乐)!
- Linux gdb调试器用法全面解析
- 简单的页面验证:验证密码是够为空和确认密码是否相同
- HDOJ 1007 Quoit Design
- redis启动脚本
- Core Animation学习笔记
- SQL基础(廿三)--- 数学函数
- 企业网站横幅焦点图切换
- FFmpeg 基本用法
- HDU 5046 Airport
- unable to resolve host address
- Keepalived + nginx实现高可用性和负载均衡