传送门

Description

求\(n\)个点凸包的周长

Solution 

计算几何打暴力必备

Code 

#include<bits/stdc++.h>
#define reg register
#define ll long long
#define db double
using namespace std; const int MN=1e5+5;
const db eps=1e-8;
int n;
struct Point{
db x,y;
Point(db x=0,db y=0):x(x),y(y){}
db mo(){return sqrt(1.*x*x+1.*y*y);}
Point operator-(const Point&o)const{return Point(x-o.x,y-o.y);}
db operator^(const Point&o)const{return x*o.y-y*o.x;}
bool operator <(const Point&o)const{return x<o.x||(x==o.x&&y<o.y);}
}p[MN];
int u[MN],d[MN],tu,td; int main()
{
scanf("%d",&n);
reg int i;
for(i=1;i<=n;++i) scanf("%lf%lf",&p[i].x,&p[i].y);
std::sort(p+1,p+n+1);
for(i=1;i<=n;++i)
{
while(tu>1&&((p[u[tu]]-p[u[tu-1]])^(p[i]-p[u[tu-1]]))>-eps) --tu;
u[++tu]=i;
}
for(i=n;i;--i)
{
while(td>1&&((p[d[td]]-p[d[td-1]])^(p[i]-p[d[td-1]]))>-eps) --td;
d[++td]=i;
}
db ans=0.;
for(i=1;i<tu;++i) ans+=(p[u[i+1]]-p[u[i]]).mo();
for(i=1;i<td;++i) ans+=(p[d[i+1]]-p[d[i]]).mo();
return 0*printf("%.2lf\n",ans);
}

Blog来自PaperCloud,未经允许,请勿转载,TKS!

最新文章

  1. [转] Oracle数据库备份与恢复 - 增量备份
  2. BNUOJ 52325 Increasing or Decreasing 数位dp
  3. Linux中TFTP使用详解
  4. S3C2440 裸机程序之音频
  5. Javascript操作Cookie的脚本 &mdash; CookieHelper
  6. 使用 Python 进行稳定可靠的文件操作
  7. 论文第4章:iOS绘图平台的实现
  8. Linux下php安装memcache扩展
  9. bzoj2096 pilots
  10. 模仿$.Callbacks实现
  11. C语言中关于scanf函数的用法
  12. [置顶] Asp.Net---css样式的使用方式
  13. PredictionIO+Universal Recommender快速开发部署推荐引擎的问题总结(2)
  14. 将html table 转成 excel
  15. 使用 ASP.NET Core MVC 创建 Web API(四)
  16. cadcam
  17. Node&lt;T&gt; 的作用
  18. centos7上安装nagios及增加监控服务器
  19. Spring源码解析二:IOC容器初始化过程详解
  20. &lt;聪明的投资者(第四版点评)&gt;读书笔记

热门文章

  1. vim打开多个文件、同时显示多个文件、在文件之间切换
  2. kali之nmap
  3. springmvc框架helloword
  4. php长连接应用
  5. Guava Cache用法介绍
  6. c# 泛型study
  7. MySQL Execution Plan--IN子查询对UPDATE语句影响
  8. 03-JavaScript语法介绍
  9. C++(四十六) — 异常处理机制、标准IO输入输出
  10. opencv图片压缩视频并读取