嘟嘟嘟




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

关键就是到\(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. wcf远程服务器返回错误404

    最近根据quartz.net 和wcf做资讯内容定时推送,wcf调用的时候出现远程服务器返回错误404,一直找不到原因是什么,客户端和服务器地址和配置都没啥问题,最后发现wcf请求数据,有传输大小限制 ...

  2. python学习之老男孩python全栈第九期_day029知识点总结——configparser模快、logging模块

    一. configparser模块 生成文档 import configparser config = configparser.ConfigParser() config[', 'Compressi ...

  3. mysql 删除某一个数据库下面的所有表,但不删除数据库

    删除某一个数据库下面的所有表,但不删除数据库.该语句经过从concat拼接,最后查询出来的是删除表的语句,然后执行那些查询出来的语句就ok了select concat(‘drop table ‘,ta ...

  4. 阿里react整合库dva demo分析 [转]

    同,也是工作中需要,用到 dva ,  也找了些文章参考知识点. 更多:http://www.cnblogs.com/heyuqing/p/6844098.html 以下内容为摘出  mark 接着踩 ...

  5. strConnection连接Access数据库

    string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;";            strConnection += @ ...

  6. android studio使用openssl

    前言 逆向的基础是开发, 逆向分析时很多时候会使用一些公开的加密函数来对数据进行加密,通过使用 openssl 熟悉下. 正文 首先得先编译出来 openssl,然后把它们复制到你的工程目录下. in ...

  7. canvas验证码 - 滑块拼图

    滑块拼图型的验证方式已经流行起来,多数的实现方式是直接加载两张分割好的图片.现在用canvas去自动修剪图片,节省修图工作量和http请求: 加载一张整图,用canvas切割缺口,缺口位置在固定范围内 ...

  8. linux 安装 zookeeper 集群

    关闭防火墙 systemctl stop firewalld.service systemctl disable firewalld.servicesystemctl status firewalld ...

  9. oracle exp dmp

    exp help=yconn scott/tiger;select * from tab;create table student(sno int, sname varchar2(10), sage ...

  10. spring boot(9)-mybatis关联映射

    一对多 查询type表的某一条数据,并且要同时查出所有typeid与之配置的user,最终要得到一个以下类型的Type对象 public class Type { String id; String ...