[BJWC2011]最小三角形
嘟嘟嘟
这一看就是平面分治的题,所以就想办法往这上面去靠。
关键就是到\(mid\)点的限制距离是什么。就是对于当前区间,所有小于这个距离的点都选出来,参与更新最优解。
假设从左右区间中得到的最优解是\(d\),那么这个限制距离就是\(\frac{d}{2}\)。这很显然,如果三角形的一条边比\(\frac{d}{2}\)还大,那么他的周长一定大于\(d\)。
因此我们选出所有小于\(\frac{d}{2}\)的点,然后比较暴力的更新答案,具体看代码。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 2e5 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n;
struct Point
{
db x, y;
bool operator < (const Point& oth)const
{
return x < oth.x;
}
Point operator - (const Point& oth)const
{
return (Point){x - oth.x, y - oth.y};
}
friend inline db dis(const Point& A)
{
return sqrt(A.x * A.x + A.y * A.y);
}
}p[maxn], b[maxn], c[maxn], tp[maxn];
bool cmpy(Point a, Point b) {return a.y < b.y;}
db solve(int L, int R)
{
if(L == R - 1) return INF;
if(L == R - 2) return dis(p[L] - p[L + 1]) + dis(p[L + 1] - p[R]) + dis(p[R] - p[L]);
int mid = (L + R) >> 1, cnt = 0;
db d = min(solve(L, mid), solve(mid, R));
db lim = d / 2;
for(int i = L; i <= R; ++i)
if(abs(p[i].x - p[mid].x) <= lim) tp[++cnt] = p[i];
sort(tp + 1, tp + cnt + 1, cmpy);
for(int i = 1, j = 1; i <= cnt; ++i)
{
for(; j <= cnt && abs(tp[j].y - tp[i].y) <= lim; ++j);
for(int k = i + 1; k < j; ++k)
for(int l = i + 1; l < k; ++l)
d = min(d, dis(tp[i] - tp[k]) + dis(tp[k] - tp[l]) + dis(tp[i] - tp[l]));
}
return d;
}
int main()
{
n = read();
for(int i = 1; i <= n; ++i) p[i].x = read(), p[i].y = read();
sort(p + 1, p + n + 1);
printf("%.6lf\n", solve(1, n));
return 0;
}
[BJWC2011]最小三角形的更多相关文章
- [BJWC2011]最小三角形(分治+最近点对)
题面:BJWC2011 最小三角形 \(solution:\) 昨天才学完平面最近点对,今天就要求平面最近的三个点,显然不是巧合. 仔细一思考,我们用来求平面最近点对的方法不就可以用到三个点上吗? 就 ...
- Luogu4423 BJWC2011 最小三角形 平面最近点对
传送门 题意:给出$N$个点,求其中周长最小的三角形(共线的也计算在内).$N \leq 2 \times 10^5$ 这道题唤起了我对平面最近点对的依稀记忆 考虑平面最近点对的分治,将分界线两边的求 ...
- bzoj2458: [BeiJing2011]最小三角形(分治+几何)
题目链接:bzoj2458: [BeiJing2011]最小三角形 学习推荐博客:分治法编程问题之最接近点对问题的算法分析 题解:先将所有点按x值排列,然后每次将当前区间[l,r]分成左右两半递归求解 ...
- BZOJ2458 Beijing2011最小三角形(分治)
类似于平面最近点对,考虑分治,即分别计算分割线两侧的最小三角形再考虑跨过线的三角形. 复杂度证明也是类似的,对于某一个点,在另一侧可能与其构成最小三角形的点在一个d*d/2的矩形内(两边之和大于第三边 ...
- BZOJ 2458 最小三角形 | 平面分治
BZOJ 2458 最小三角形 题面 一个平面上有很多点,求他们中的点组成的周长最小的三角形的周长. 题解 跟平面最近点对差不多,也是先把区间内的点按x坐标从中间分开,递归处理,然后再处理横跨中线的三 ...
- BZOJ2458:[BJOI2011]最小三角形——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2458 Description Xaviera现在遇到了一个有趣的问题. 平面上有N个点,Xavier ...
- bzoj 2458: [BeiJing2011]最小三角形 题解
[前言]话说好久没有写题解了.到暑假了反而忙.o(╯□╰)o [原题] 2458: [BeiJing2011]最小三角形 Time Limit: 10 Sec Memory Limit: 128 M ...
- bzoj-2458 2458: [BeiJing2011]最小三角形(计算几何+分治)
题目链接: 2458: [BeiJing2011]最小三角形 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1101 Solved: 380 Des ...
- 分治 - 计算几何 - BZOJ2458,[BeiJing2011]最小三角形
http://www.lydsy.com/JudgeOnline/problem.php?id=2458 [BeiJing2011]最小三角形 描述 Frisk现在遇到了一个有趣的问题. 平面上有N个 ...
随机推荐
- iOS交互h5——user-agent
User-Agent(用户代理)字符串是Web浏览器用于声明自身型号版本并随HTTP请求发送给Web服务器的字符串,在Web服务器上可以获取到该字符串. 在公司产品中,在userAgent中增加了XX ...
- VS2015编译OpenSSL
概述 OpenSSL 是一个开源的第三方库,它实现了 SSL(Secure SocketLayer)和 TLS(Transport Layer Security)协议,被广泛企业应用所采用.对于一般的 ...
- git分支简介,理解HEAD,master
为了真正理解 Git 处理分支的方式,我们需要回顾一下 Git 是如何保存数据的. 或许你还记得 起步 的内容,Git 保存的不是文件的变化或者差异,而是一系列不同时刻的文件快照. 在进行提交操作时, ...
- SpringBoot整合mybatis-plus入门
pom.xml中加入如下依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>myba ...
- 宜立方商城中,mvn报错'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-webmvc:jar报错
'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:s ...
- Dijkstra Java
https://leetcode.com/problems/network-delay-time/ /* Java program to find a Pair which has maximum s ...
- SpringBoot 之配置server 信息
一.修改端口号 spring-boot 默认的端口号是8080,如需修改. 1.新建一个src/main/resources 文件夹 2.在这个文件夹下新建一个application.properti ...
- lsnrctl 与 tnsnames.ora 的联系
平台:Windoxs XP+Oracle 11G 当使用oralce的 Net Manager创建了一个名为“L3”的Listener后,要想使用lsnrctl启动和关闭 L3 还必须在tnsname ...
- Django settings介绍
""" Django settings for macboy project. Generated by 'django-admin startproject' usin ...
- Others
1.可迭代对象可以被for循环获取 2.可变与不可变对象 不可变对象:数字 字符串 元组 所谓不可变是值和身份都不变 赋值时开辟新内存空间生成新值 可变 对象:列表 字典 集合 ...