LINK:平面最近点对 加强版

有一种分治的做法 因为按照x排序分治再按y排序 可以证明每次一个只会和周边的六个点进行更新。

好像不算很难 这里给出一种随机化的做法。

前置知识是旋转坐标系 即以某个点位旋转中心旋转某个点的位置。

设旋转中心为(x2,y2).

旋转公式:x=(x1-x2)cos(a)-(y1-y2)sin(a)+x2;y=(x1-x2)sin(a)+(y1-y2)cos(a)+y2;

那么以原点为旋转中心 那其实是在旋转坐标系。

旋转之后考虑按照x排序 那么每个点向后面几个点暴力更新答案即可。

显然这是一个随机的过程 容易发现对于最小值得点对有极大几率可以被便利到 所以可以认为是正确.

code
//#include<bits\stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define ldb long double
#define pb push_back
#define put_(x) printf("%d ",x);
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define gi(x) scanf("%lf",&x)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define gc(a) scanf("%s",a+1)
#define rep(p,n,i) for(RE int i=p;i<=n;++i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define fep(n,p,i) for(RE int i=n;i>=p;--i)
#define vep(p,n,i) for(RE int i=p;i<n;++i)
#define pii pair<int,int>
#define mk make_pair
#define RE register
#define P 1000000007
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define uint unsigned long long
#define ui unsigned
#define EPS 1e-8
#define sq sqrt
#define mod 1000000007
#define S second
#define F first
#define pf(x) ((x)*(x))
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
RE int x=0,f=1;RE char ch=getc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
return x*f;
}
const int MAXN=200010;
const db Pi=acos(-1.0);
int n,m;db ans=1e10;
struct wy{db x,y;}t[MAXN];
inline int cmp(wy a,wy b){return a.x<b.x;}
inline db dis(wy a,wy b){return sqrt(pf(a.x-b.x)+pf(a.y-b.y));}
inline void around(db d)
{
d=d/180*Pi;
rep(1,n,i)
{
db x=t[i].x,y=t[i].y;
t[i].x=x*cos(d)-y*sin(d);
t[i].y=x*sin(d)+y*cos(d);
}
sort(t+1,t+1+n,cmp);
rep(1,n,i)
for(int j=i+1;j<=i+5&&j<=n;++j)
ans=min(ans,dis(t[i],t[j]));
}
int main()
{
freopen("1.in","r",stdin);
srand(time(0));
get(n);
rep(1,n,i){int get(x);t[i]=(wy){x,read()};}
around(0);around(rand()%360);printf("%.4lf",ans);
return 0;
}

最新文章

  1. python 小程序 比较目录间的差异
  2. maven 问题解决 tools以及jconsole两个jar包 无效
  3. SQL Server 2008 R2没有卸载干净
  4. 通过top命令发现plymouthd进程cpu负载达到近100% 解决办法
  5. poj 3422 (费用流)
  6. Fireworks Extension —— 开发篇(Dom模型)
  7. 【经验随笔】MYSQL表加锁升级导致数据库访问失败
  8. 数据结构基础(21) --DFS与BFS
  9. python3爬虫 - 利用浏览器cookie登录
  10. @RequestParam、@RequestBody和@ModelAttribute区别
  11. BZOJ3224/LOJ104 普通平衡树 treap(树堆)
  12. Python------excel读、写、拷贝
  13. cobub razor 安装及使用
  14. php5.3.x连接MS SQL server2008
  15. UVa 11019 Matrix Matcher - Hash
  16. css扩大超链接的点击范围
  17. 《深入浅出MFC》系列之运行时类型识别(RTTI)
  18. Nagios服务器端配置文件详解
  19. scrapy框架(2)
  20. Code Signal_练习题_palindromeRearranging

热门文章

  1. RESTful API 规范(一)
  2. mysql数据库 创建、查看、重命名、复制和删除的基本操作
  3. Fetch.AI 首席技术官Toby Simpson参与AMA活动
  4. Python 的print报错SyntaxError: invalid syntax
  5. C#数据类型及其转换详解
  6. VulnHub::DC-1
  7. Java 字符串比较、拼接问题
  8. 数据可视化实例(十六):有序条形图(matplotlib,pandas)
  9. Python之爬虫(十五) Scrapy框架的命令行详解
  10. Ethical Hacking - NETWORK PENETRATION TESTING(4)