【题目链接】

http://poj.org/problem?id=3714

【算法】

分治求平面最近点对

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100010
const double INF = 1e10; int T,i,n; struct info
{
double x,y;
int opt;
} a[MAXN<<]; inline bool cmpx(info a,info b)
{
return a.x != b.x ? a.x < b.x : a.y < b.y;
}
inline bool cmpy(info a,info b)
{
return a.y < b.y;
}
double dist(info a,info b)
{
return (a.opt != b.opt) ? sqrt(abs(a.x - b.x) * abs(a.x - b.x) + abs(a.y - b.y) * abs(a.y - b.y)) : INF;
}
inline double Closest_Pair(int l,int r)
{
int i,j,mid,len = ;
static info s[MAXN];
double d;
if (l == r) return INF;
if (l + == r) return dist(a[l],a[r]);
mid = (l + r) >> ;
d = min(Closest_Pair(l,mid),Closest_Pair(mid+,r));
for (i = l; i <= r; i++)
{
if (abs(a[mid].x - a[i].x) <= d) s[++len] = a[i];
}
sort(s+,s+len+,cmpy);
for (i = ; i <= len; i++)
{
for (j = i + ; j <= len && s[j].y - s[i].y <= d; j++)
{
d = min(d,dist(s[i],s[j]));
}
}
return d;
} int main()
{ scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (i = ; i <= n; i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
a[i].opt = ;
}
for (i = n + ; i <= * n; i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
a[i].opt = ;
}
sort(a+,a+*n+,cmpx);
printf("%.3lf\n",Closest_Pair(,n<<));
} return ; }

【POJ 3714】 Raid的更多相关文章

  1. 【POJ 3714】Raid

    [题目链接]:http://poj.org/problem?id=3714 [题意] 给你两类的点; 各n个; 然后让你求出2*n个点中的最近点对的距离; 这里的距离定义为不同类型的点之间的距离; [ ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. Linux(Centos7)下搭建SVN服务器(新手上路)

    以前都是别人直接给地址在svn上,下载或者上传东西,如今要自己建一个版本库用来存放东西.1.安装svnyum install -y subversion 2.查看svn安装位置还有哪些文件rpm -q ...

  2. Java笔记——String、StringBuffer和StringBuilder类

    String类是不可变类,即一旦一个String对象被创建以后,包含在这个对象中的字符串序列是不可改变的,直至这个对象被销毁.   StringBuffer对象则代表一个字符序列可变的字符串,当一个S ...

  3. 一段简单的手写Java计算器代码

    import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.lang.*; public class Calc ...

  4. [USACO06JAN] 牛的舞会 The Cow Prom

    题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...

  5. linux性能优化cpu-02平均负载

    每次我们系统变慢时,我们通常做的第一件事就是top命令或者uptime命令,看一下系统的负载情况,比如下面: 我在命令行中输入uptime 22:15:51    表示当前系统时间 up 13 min ...

  6. keep

    简介 什么是keepalived呢?keepalived是实现高可用的一种轻量级的技术手段,主要用来防止单点故障(单点故障是指一旦某一点出现故障就会导致整个系统架构的不可用)的发生.之所以说keepa ...

  7. response对象处理HTTP文件头(禁用缓存、设置页面自动刷新、定时跳转网页)

    response对象处理HTTP文件头 制作人:全心全意 禁用缓存 在默认情况下,浏览器将会对显示的网页内容进行缓存.这样,当用户再次访问相关网页时,浏览器会判断网页是否有变化,如果没有变化则直接显示 ...

  8. Yii 时间日期组件与composer 下载中出现的问题

    首先本篇主要讲3点 一个Yii时间日期组件的两种用法 笔者使用composer下载该组件时出现问题的解决办法 1.composer下载出现的问题 file could not be downloade ...

  9. POJ3624 0-1背包(dp+滚动数组)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 47440   Accepted: 20178 ...

  10. 【03】WAMPServer集成环境下载和安装

    WAMPServer集成环境下载和安装1.W:windows,A:Apache,M:MySQL,P:PHP2.下载WAMP开发包网址:www.wampserver.com           3.安装 ...