嘟嘟嘟




这一看就是平面分治的题,所以就想办法往这上面去靠。

关键就是到\(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]最小三角形的更多相关文章

  1. [BJWC2011]最小三角形(分治+最近点对)

    题面:BJWC2011 最小三角形 \(solution:\) 昨天才学完平面最近点对,今天就要求平面最近的三个点,显然不是巧合. 仔细一思考,我们用来求平面最近点对的方法不就可以用到三个点上吗? 就 ...

  2. Luogu4423 BJWC2011 最小三角形 平面最近点对

    传送门 题意:给出$N$个点,求其中周长最小的三角形(共线的也计算在内).$N \leq 2 \times 10^5$ 这道题唤起了我对平面最近点对的依稀记忆 考虑平面最近点对的分治,将分界线两边的求 ...

  3. bzoj2458: [BeiJing2011]最小三角形(分治+几何)

    题目链接:bzoj2458: [BeiJing2011]最小三角形 学习推荐博客:分治法编程问题之最接近点对问题的算法分析 题解:先将所有点按x值排列,然后每次将当前区间[l,r]分成左右两半递归求解 ...

  4. BZOJ2458 Beijing2011最小三角形(分治)

    类似于平面最近点对,考虑分治,即分别计算分割线两侧的最小三角形再考虑跨过线的三角形. 复杂度证明也是类似的,对于某一个点,在另一侧可能与其构成最小三角形的点在一个d*d/2的矩形内(两边之和大于第三边 ...

  5. BZOJ 2458 最小三角形 | 平面分治

    BZOJ 2458 最小三角形 题面 一个平面上有很多点,求他们中的点组成的周长最小的三角形的周长. 题解 跟平面最近点对差不多,也是先把区间内的点按x坐标从中间分开,递归处理,然后再处理横跨中线的三 ...

  6. BZOJ2458:[BJOI2011]最小三角形——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2458 Description Xaviera现在遇到了一个有趣的问题. 平面上有N个点,Xavier ...

  7. bzoj 2458: [BeiJing2011]最小三角形 题解

    [前言]话说好久没有写题解了.到暑假了反而忙.o(╯□╰)o [原题] 2458: [BeiJing2011]最小三角形 Time Limit: 10 Sec  Memory Limit: 128 M ...

  8. bzoj-2458 2458: [BeiJing2011]最小三角形(计算几何+分治)

    题目链接: 2458: [BeiJing2011]最小三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1101  Solved: 380 Des ...

  9. 分治 - 计算几何 - BZOJ2458,[BeiJing2011]最小三角形

    http://www.lydsy.com/JudgeOnline/problem.php?id=2458 [BeiJing2011]最小三角形 描述 Frisk现在遇到了一个有趣的问题. 平面上有N个 ...

随机推荐

  1. 【转】HttpServletRequestWrapper 实现xss注入

    这里说下最近项目中我们的解决方案,主要用到commons-lang3-3.1.jar这个包的org.apache.commons.lang3.StringEscapeUtils.escapeHtml4 ...

  2. lombok入门

    pom.xml加入依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lo ...

  3. Implementation:Sunday 字符串匹配

    int sunday(string str, string pattern) { int str_len = str.length(); int pat_len = pattern.length(); ...

  4. hello Groovy

    Groovy [rocky@www ~]$ curl -s get.sdkman.io 1. 下载 [rocky@www Downloads]$ wget https://dl.bintray.com ...

  5. 使用99元一年的256MB高性能阿里云Redis加速Discuz论坛

    介绍 Discuz是一个常见的论坛,支持使用Redis来对论坛进行加速访问,对于访问量比较大的论坛能够取到很好的作用,本文介绍如何使用阿里云高性价比256MBRedis来加速该论坛. 阿里云Redis ...

  6. JSPatch 可以让你用 JavaScript 书写原生 iOS APP

    简介   JSPatch 可以让你用 JavaScript 书写原生 iOS APP.只需在项目引入极小的引擎,就可以使用 JavaScript 调用任何 Objective-C 的原生接口,获得脚本 ...

  7. Java反射机制动态代理

    1.什么事反射机制动态代理 在一段代码的前后动态执行其他操作,比如有一个方法是往数据库添加一个记录,我们可以通过动态代理,在操作数据库方法的前和后添加代码执行打开数据库连接和关闭数据库连接. 2.演示 ...

  8. 180415_判断闰年的思路及三种 java 实现

    世纪年:能整除 100 的年份 普通年:不能整除 100 的年份 闰年:一年有 366 天,二月有 29 天 平年:一年有 365 天,二月有 28 天 对于世纪年:能整除 400 为闰年,否则为平年 ...

  9. 一、vue:如何新建一个vue项目

    比较好用的一个脚手架:https://a1029563229.gitbooks.io/vue/content/cooking-cli.html 创建一个vue项目的流程: 1.安装node,版本号必须 ...

  10. 【转】证书的应用之一 —— TCP&SSL通信实例及协议分析(下)

    原文链接 前面两部分分别讲解了如何在.net程序中使用SSL实现安全通信以及SSL的通信过程,并通过抓包工具具体分析了ssl的握手过程,本文通过一个demo来模拟ssl协议,在TCP之上实现自己的安全 ...