嘟嘟嘟




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

关键就是到\(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. 设置TableView section header的颜色

      - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInte ...

  2. SDWebImage实现图片展示、缓存、清除缓存

    1. /* 图片显示 */ [self.imageView sd_setImageWithURL:[NSURL URLWithString:urlString]];                [s ...

  3. 撩课-Web大前端每天5道面试题-Day19

    1.实现一个函数clone,可以对JavaScript中的5种主要的数据类型(包括Number.String.Object.Array.Boolean)进行值复制 考察点1:对于基本数据类型和引用数据 ...

  4. SpringBoot集成Jersey

    SpringBoot集成Jersey 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> & ...

  5. Linux下svn的安装与部署

    最近工作碰到一个问题,我和一个同伙负责开发一个管理系统,基于原来的代码上进行修改,每当他修改之后,我要再修改都要和他确定是不是最新的文件,才能进行修改.非常影响工作的效率,所以在网上找了关于svn的使 ...

  6. Linux学习2-Linux分区方式

    1.磁盘分区 磁盘分区是使用分区编辑器(partition editor)在磁盘上划分几个逻辑部分.碟片一旦划分成数个分区(partition),不同类的目录与文件可以存储进不同的分区. 未经过分类整 ...

  7. fontforge制作自定义字体及在手机上应用举例——张鑫旭

    一.看似无关紧要的事件背景 之所以花时间折腾fontforge这个软件,去制作什么自定义的字体是有原因滴. 之前提过,最近我抽空将公司的手机软件HTML5网页化.期间碰到这么一个问题,页面低栏上的电话 ...

  8. 基于AlipayJSBridge封装的H5网页支付宝打赏、网站打赏、个人免签支付,支付宝转账打赏支付组件

    之前公司要做个打赏用户的功能,网站查询一些资料之后把一些api封装之后提供了一个demo组件供大家下载:扫描下图二维码 功能: 支付宝H5 Js方案,调起应用内页面,自动设定转账金额和收款理由,用户付 ...

  9. Yii 之components

    当我们创建一个module的时候,对应的path alias就已经创建.比如我们定义了一个module: www 1 2 3 4 5 'modules'=>array(     'www'=&g ...

  10. Eclipse Ctrl + H 搜索文件不覆盖已打开文件解决办法

    1.windows------->preferences