[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个 ...
随机推荐
- ZAB 算法
ZAB (Zookeeper Atomic Broadcast ) zookeeper原子消息广播协议 保证:分布式数据一致性 所有事务请求必须由一个全局唯一的服务器来协调处理,这样的服务器被称为 ...
- SpringMVC+MyBatis+MySQL 8小时链接断开
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...
- lua模块化
main.lua local main = require("my") main.greeting() my.lua local foo = {} local function g ...
- P/Invoke出现错误 System.NullReferenceException”类型的未经处理的异常在 未知模块。 中发生 未将对象引用设置到对象的实例。
问题 “System.NullReferenceException”类型的未经处理的异常在 未知模块. 中发生 未将对象引用设置到对象的实例. 解决方案 1.尝试 用管理员身份运行CMD,输入nets ...
- 使用手机预览移动端项目(Vue)
1.在 npm run dev 启动Vue项目之后.例:http://localhost:8095/#/chatList 2.查看本机的 IP (WIN + R + cmd ) 输入 ipconfig ...
- OG数据预处理
1.影像处理 ogCalcExtent --srs EPSG:26711 --inputdir D:/software/preprocess/data/bugaboos/ --filet ...
- hidden field implements session
隐藏域实现会话管理概述 如果你正在制作一个网络问卷,由于问卷内容很长,因此必须分几个页面,上一页面作答完后,必须请求服务器显示下一个页面. 但是在HTTP协议中,服务器并不会记得上一次请求的状态.既然 ...
- 登录MySQL提示ERROR 1045 (28000)错误解决方法
今天,登录服务器准备修改数据库的一些东西.但输入密码,却进不了数据库并提示一个错误,如下图 再确认密码没错的情况下,还是进不了数据库.便在网上找到了解决方法,记录下来,供参考学习. 解决方法: 总体思 ...
- spring boot(11)-druid监控
druid druid是和tomcat jdbc一样优秀的连接池,出自阿里巴巴.关于druid连接池参数,参考 https://github.com/alibaba/druid/wiki/DruidD ...
- Mysql5.7 的错误日志中最常见的note级别日志解释
在使用mysql5.7的时候,发现了不少在mysql5.6上不曾见过的日志,级别为note, 最常见的note日志以下三种,下面我们来逐个解释. 第一种,Aborted connectio ...