题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670

用叉积判断。注意两端的平行于 y 轴的。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define db double
using namespace std;
const int N=,INF=1e7;
int n,sta[N],top;db ans;
struct Node{
int x,y;
Node(int x=,int y=):x(x),y(y) {}
bool operator< (const Node &b)const
{return x<b.x||(x==b.x&&y<b.y);}
Node operator- (const Node &b)const
{return Node(b.x-x,b.y-y);}
}a[N];
ll Sqr(int x){return (ll)x*x;}
ll Cross(Node a,Node b){return (ll)a.x*b.y-(ll)a.y*b.x;}
db dist(Node a,Node b){return sqrt(Sqr(a.x-b.x)+Sqr(a.y-b.y));}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
sort(a+,a+n+);
for(int i=;i<=n;i++)
{
while(top>&&Cross(a[i]-a[sta[top]],a[i]-a[sta[top-]])>=)top--;
sta[++top]=i;
}
for(int i=;i<=top;i++)ans+=dist(a[sta[i-]],a[sta[i]]);
for(int i=;i<=n;i++)a[i].y=INF-a[i].y+;
sort(a+,a+n+);
top=;
for(int i=;i<=n;i++)
{
while(top>&&Cross(a[i]-a[sta[top]],a[i]-a[sta[top-]])>=)top--;
sta[++top]=i;
}
for(int i=;i<top;i++)ans+=dist(a[sta[i-]],a[sta[i]]);
if(top>&&a[sta[top]].x!=a[sta[top-]].x)ans+=dist(a[sta[top-]],a[sta[top]]);
if(a[].x==a[].x)ans+=abs(a[].y-a[].y);
printf("%.2f\n",ans);
return ;
}

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护城河的挖掘

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

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

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

  4. bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘【凸包】

    凸包模板 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> ...

  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. 【Mongodb】数据库操作--备份、还原、导出和导入

    文章转载自点这里 mongodb数据备份和还原主要分为二种,一种是针对于库的mongodump和mongorestore,一种是针对库中表的mongoexport和mongoimport. mongo ...

  2. GitHub:Git的使用

    1.下载安装后设置姓名和邮箱地址 $ git config --global user.name "yourGithubName" $ git config --global us ...

  3. js获取显示器、页面等高度 (转)

    网页可见区域宽:document.body.clientWidth网页可见区域高:document.body.clientHeight网页可见区域宽:document.body.offsetWidth ...

  4. Java 进阶7 并发优化 5 并发控制板方法

    Java 进阶7 并发优化 5 并发控制板方法 20131114 前言:          Java 中多线程并发程序中存在线程安全的问题,之前学习 Java的同步机制,掌握的同步方法只有一种就是使用 ...

  5. ES的Zen发现机制

    ES的Zen发现机制 Zen发现机制是ElasticSearch默认的发现模块.它提供的是单播发现,但是可被拓展为支持云环境下或者其他形式的发现机制.zen 发现模块集成了其他模块,如在发现期间,节点 ...

  6. Java基础学习-内部类

    /*内部类: 成员内部类 局部内部类 匿名内部类*/ package insideclass; /*成员内部类: * 在类的成员位置,和成员变量,成员方法的位置是一样的. * 内部类可以直接访问为外部 ...

  7. windows下gvim搭建IDE

    原文转载自:手把手教你把Vim改装成一个IDE编程环境(图文) 如侵犯您的版权,请联系:windeal12@qq.com By: 吴垠 Date: 2007-09-07 Version: 0.5 Em ...

  8. jQuery 选择器效率

    http://blog.csdn.net/cxl444905143/article/details/48808809 ID > Tag > Class ID 选择器是速度最快的,这主要是因 ...

  9. Apache .htaccess文件

    今天在将ThinkPHP的URL模式由普通模式(URL_MODE=1)http://localhost/mythinkphp/index.php/Index/user/id/1.html改为重写模式 ...

  10. Javascript MV framework 对比

    Javascript 最近的framework笔记多,大致可分以下3类.单向绑定简单直接.ajax从service拿数据传递给viewtemplate进行绑定.当然这个过程也可以在服务器端来做,.ne ...