凸包模板

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=5005;
int n,w,top;
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a) const
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a) const
{
return dian(x-a.x,y-a.y);
}
}a[N],s[N],d;
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
bool cmp(const dian &x,const dian &y)
{
double ar=cj(x-d,y-d);
return ar>0||(ar==0&&x.x<y.x);
}
double dis(dian a,dian b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read();
d.x=1e9,d.y=1e9;
for(int i=1;i<=n;i++)
{
a[i].x=read(),a[i].y=read();
if(a[i].x<d.x||(a[i].x==d.x&&a[i].y<d.y))
w=i,d=a[i];
}
swap(a[w],a[n]);
n--;
sort(a+1,a+1+n,cmp);
s[++top]=d;s[++top]=a[1];
for(int i=2;i<=n;i++)
{
while(top>1&&cj(s[top]-a[i],s[top-1]-a[i])>=0)
top--;
s[++top]=a[i];
}
double ans=0;
s[top+1]=s[1];
for(int i=1;i<=top;i++)
ans+=dis(s[i],s[i+1]);
printf("%.2lf\n",ans);
return 0;
}

bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘【凸包】的更多相关文章

  1. bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 -- 凸包

    1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec  Memory Limit: 64 MB Description 为了防止 ...

  2. bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 用叉积判断.注意两端的平行于 y 轴的. #include<cstdio> ...

  3. BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘

    Description 求凸包周长. Sol 凸包+计算几何. 这好像叫什么 Graham Scan 算法... 这个可以求凸包的周长,直径,面积. 选择一个基点,然后按极角排序,最后用一个栈一直维护 ...

  4. 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)

    链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  5. 【BZOJ】1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1670 裸打了凸包.. #include <cstdio> #include <cs ...

  6. BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包

    BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包 Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场 ...

  7. BZOJ1670 [Usaco2006 Oct]Building the Moat护城河的挖掘

    裸的凸包...(和旋转卡壳有什么关系吗...蒟蒻求教T T) 话说忘了怎么写了...(我以前都是先做上凸壳再做下凸壳的说) 于是看了下hzwer的写法,用了向量的点积,方便多了,于是果断学习(Orz) ...

  8. 【计算几何】【凸包】bzoj1670 [Usaco2006 Oct]Building the Moat护城河的挖掘

    #include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define ...

  9. bzoj 1670 Building the Moat护城河的挖掘 —— 凸包

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 单调栈维护凸包即可,用叉积判断: 维护上凸壳,然后把所有点的纵坐标翻转再求上凸壳即可, ...

随机推荐

  1. POJ 1988相对偏移

    //不容易啊,终于自己a了一道这种类型的题 // #include<stdio.h> #include<iostream> using namespace std; const ...

  2. 一个Java开发的Python之路----------------(一)

    最近开始学习Python了,主要是因为现在在给海航通过JAVA写CMDB运维管理平台,我就是作为唯一一个坐在运维屋里的开发,又当爹,又当妈,前端,后台,测试,设计,需求, 发布,统统一把抓!!在Git ...

  3. Thinkphp5.0 的使用模型Model删除数据

    Thinkphp5.0 的使用模型Model删除数据 一.使用destory()删除数据 //删除id为3的记录 $res = User::destroy(3); //返回影响的行数 dump($re ...

  4. 洛谷—— P3370 【模板】字符串哈希

    P3370 [模板]字符串哈希 题目描述 如题,给定N个字符串(第i个字符串长度为Mi,字符串内包含数字.大小写字母,大小写敏感),请求出N个字符串中共有多少个不同的字符串. 友情提醒:如果真的想好好 ...

  5. some 算法

    矩阵变换:: 请用一条语句将: arr = [[1, 2, 3, 'a'], [4, 5, 6, 'b'], [7, 8, 9, 'c']] 转换装置矩阵为: [[1, 4, 7], [2, 5, 8 ...

  6. 【Nginx】负载均衡-加权轮询策略剖析

    转自:江南烟雨 本文介绍的是客户端请求在多个后端服务器之间的均衡,注意与客户端请求在多个nginx进程之间的均衡相区别. 如果Nginx是以反向代理的形式配置运行,那么对请求的实际处理需要转发到后端服 ...

  7. SSD硬盘安装系统后要做的事

    1***cmd>fsutil behavior query DisableDeleteNotify 0如果返回值是0,则代表TRIM处于开启状态:反之如果返回值是1,则代表TRIM处于关闭状态2 ...

  8. BZOJ 2208 JSOI2010 连通数 Tarjan+拓扑排序

    题目大意:给定一个n个点的有向图,求有多少点对(x,y),使x沿边可到达y 设f[i][j]为从i到j是否可达 首先强联通分量中的随意两个点均可达 于是我们利用Tarjan缩点 缩点之后是一个拓扑图. ...

  9. C#获取当前活动窗口句柄

    c# 获取当前活动窗口句柄,获取窗口大小及位置 2018年04月26日 13:48:21 漂泊_人生 阅读数:1889   需调用API函数 需在开头引入命名空间using System.Runtim ...

  10. 【图像处理】基于OpenCV底层实现的图片旋转

    image processing 系列 [图像处理]直方图匹配 [图像处理]高斯滤波.中值滤波.均值滤波 图片旋转,本质上是对旋转后的图片中每一个像素点计算在原图的位置.然后照搬过来就好. (多说一句 ...