博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【洛谷 P2742】【模板】二维凸包
阅读量:6852 次
发布时间:2019-06-26

本文共 1170 字,大约阅读时间需要 3 分钟。

二维凸包板子。。有时间会补总结的。

#include 
#include
#include
using namespace std;const int MAXN = 10010;struct point{ double x, y;}p[MAXN];int cmp1(const point a, const point b){ return a.x == b.x ? a.y < b.y : a.x < b.x;}double k(point a, point b){ return a.x == b.x ? 1e18 : (b.y - a.y) / (b.x - a.x);}double dis(point a, point b){ double px = b.x - a.x, py = b.y - a.y; return sqrt(px * px + py * py);}int n, top, st[MAXN];double ans;int main(){ scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%lf%lf", &p[i].x, &p[i].y); sort(p + 1, p + n + 1, cmp1); for(int i = 1; i <= n; ++i){ while((top > 1 && k(p[st[top - 1]], p[i]) < k(p[st[top - 1]], p[st[top]]))) --top; st[++top] = i; } for(int i = 2; i <= top; ++i) ans += dis(p[st[i]], p[st[i - 1]]); top = 0; for(int i = 1; i <= n; ++i){ while((top > 1 && k(p[st[top - 1]], p[i]) > k(p[st[top - 1]], p[st[top]]))) --top; st[++top] = i; } for(int i = 2; i <= top; ++i) ans += dis(p[st[i]], p[st[i - 1]]); printf("%.2lf\n", ans); return 0;}

转载于:https://www.cnblogs.com/Qihoo360/p/10315431.html

你可能感兴趣的文章
CISCO路由器配置基础(3)
查看>>
linux下通过串口登陆交换机
查看>>
微信公众平台群发规则说明
查看>>
LINUX下直接使用ISO文件
查看>>
第四章 apache的工作模式
查看>>
mysql备份和恢复总结
查看>>
软件明明已经删除 控制面板里还有名称
查看>>
深入浅出的SQL server 查询优化
查看>>
Hyper-V vNext新的虚拟机配置文件、配置版本
查看>>
通俗易懂,各常用线程池的执行 流程图
查看>>
CentOS 6.4 安装python2.7/mysqldb/ipython
查看>>
hive0.11 hiveserver custom认证bug
查看>>
Windows Phone SDK 8.0 新特性-Speech
查看>>
VS~单步调试DLL
查看>>
MyEclipse环境下Hibernate入门实例
查看>>
VC+CSocket文件传送示例
查看>>
职业生涯中的选择时机非常重要,各种条件还没成熟时的时候,因为诱惑而贸然行事,只会得到适得其反的结果...
查看>>
[WebDevelopment]搜索引擎优化(SEO)工具包
查看>>
Symbian OS开发入门(二) :VS2003环境下Symbian工程的导入与建立
查看>>
RequiredFieldValidator 根据group组来触发验证
查看>>