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