【POJ 3714】Raid
【题目链接】:http://poj.org/problem?id=3714
【题意】
给你两类的点;
各n个;
然后让你求出2*n个点中的最近点对的距离;
这里的距离定义为不同类型的点之间的距离;
【题解】
分治法;
不断划分小区间;
求出小区间内的最小值;
为后面的大区间剪枝;
只是要求点的类型不同才能剪枝了;
【Number Of WA】
0
【完整代码】
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5+100;
const LL oo = 5e18;
struct node{
LL x,y;
int p;
};
int n;
node a[N],b[N];
bool cmp1(node a,node b){
return a.x < b.x;
}
bool cmp2(node a,node b){
return a.y < b.y;
}
LL sqr(LL x){
return x*x;
}
LL dis(node a,node b){
LL temp = 0;
temp+=sqr(a.x-b.x);
temp+=sqr(a.y-b.y);
return temp;
}
LL solve(int l,int r){
LL ret = oo;
if (l>=r) return ret;
if (l+1==r) {
if (a[l].p!=a[r].p)
return dis(a[l],a[r]);
else
return ret;
}
int m = (l+r)>>1;
LL ret1 = solve(l,m),ret2 = solve(m+1,r),temp;
ret = min(ret1,ret2);
int k = 0;
rep2(i,m,l){
temp =sqr(a[m].x-a[i].x);
if (temp>ret && a[m].p != a[i].p) break;
b[++k] = a[i];
}
rep1(i,m+1,r){
temp = sqr(a[m].x-a[i].x);
if (temp>ret && a[m].p != a[i].p) break;
b[++k] = a[i];
}
sort(b+1,b+1+k,cmp2);
rep1(i,1,k){
rep1(j,i+1,k){
if (b[i].p==b[j].p) continue;
temp = sqr(b[i].y-b[j].y);
if (temp > ret) break;
temp = dis(b[i],b[j]);
if (temp < ret) ret = temp;
}
}
return ret;
}
int main(){
//Open();
Close();
int T;
cin >> T;
while (T--){
cin >> n;
rep1(i,1,n){
cin >> a[i].x >> a[i].y;
a[i].p = 0;
}
rep1(i,n+1,2*n){
cin >> a[i].x >> a[i].y;
a[i].p = 1;
}
n<<=1;
sort(a+1,a+1+n,cmp1);
cout << fixed << setprecision(3) << double (sqrt(1.0*solve(1,n))) << endl;
}
return 0;
}
【POJ 3714】Raid的更多相关文章
- 【POJ 3714】 Raid
[题目链接] http://poj.org/problem?id=3714 [算法] 分治求平面最近点对 [代码] #include <algorithm> #include <bi ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- Android开发进度04
1,今日:目标:实现登录和注册功能 2,昨天:完成登录和注册的界面以及后台数据库的操作 3,收获:会使用SQlite数据库的操作语句 4,问题:登录时出现问题(登录不上去)
- 常见的版本号及Springcloud的版本
谈谈软件版本号的认识 一.常见版本号说明 举个瓜:2.0.3 RELEASE 2:主版本号,当功能模块有较大更新或者整体架构发生变化时,主版本号会更新 0:次版本号.次版本表示只是局部的一些变动. 2 ...
- 题解 CF1051F 【The Shortest Statement】
这道题思路比较有意思,第一次做完全没想到点子上... 看到题目第一反应是一道最短路裸题,但是数据范围1e5说明完全不可能. 这个时候可以观察到题目给出了一个很有意思的条件,就是说边最多比点多20. 这 ...
- url中jsessionid的理解
(1) 这是一个保险措施 因为Session默认是需要Cookie支持的 但有些客户浏览器是关闭Cookie的 这个时候就需要在URL中指定服务器上的session标识,也就是5F4771183629 ...
- Jenkins学习总结(4)——持续集成,持续交付,持续部署之间的区别
经常会听到持续集成,持续交付,持续部署,三者究竟是什么,有何联系和区别呢? 假如把开发工作流程分为以下几个阶段: 编码 -> 构建 -> 集成 -> 测试 -> 交付 -> ...
- ubuntu16.04环境下安装配置openface人脸识别程序
参考http://blog.csdn.net/weixinhum/article/details/77046873 最近项目需要用到人脸训练和检测的东西,选用了OpenFace进行,因而有此文. 本人 ...
- javascript系列-class10.DOM(下)
1.node节点(更详细的获取(设置)页面中所有的内容) 根据 W3C 的 HTML DOM 标准,HTML 文档中的所有内容都是节点: 元素是节点的别称,节点包含元素当然节点还有 ...
- 4.git "Could not read from remote repository.Please make sure you have the correct access rights."解决方案
转自:https://zhiku8.com/git-could-not-read-from-remote-repository.html 我们在使用git clone 或其他命令的时候,有时候会遇到这 ...
- UISrcoll控件简单介绍
UISrcoll控件,简单的说就是让界面滑动 当使用uiimageview的时候,给控件设置图片素材时,图片的大小会根据控件的大小,自动做缩放 当使用uibutton的时候,如果是设置背景图,name ...
- spark集群体系结构