bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包
题目: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护城河的挖掘——凸包的更多相关文章
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 -- 凸包
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MB Description 为了防止 ...
- BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
Description 求凸包周长. Sol 凸包+计算几何. 这好像叫什么 Graham Scan 算法... 这个可以求凸包的周长,直径,面积. 选择一个基点,然后按极角排序,最后用一个栈一直维护 ...
- 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)
链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘【凸包】
凸包模板 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> ...
- 【BZOJ】1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
http://www.lydsy.com/JudgeOnline/problem.php?id=1670 裸打了凸包.. #include <cstdio> #include <cs ...
- BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包
BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包 Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场 ...
- BZOJ1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
裸的凸包...(和旋转卡壳有什么关系吗...蒟蒻求教T T) 话说忘了怎么写了...(我以前都是先做上凸壳再做下凸壳的说) 于是看了下hzwer的写法,用了向量的点积,方便多了,于是果断学习(Orz) ...
- 【计算几何】【凸包】bzoj1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define ...
- bzoj 1670 Building the Moat护城河的挖掘 —— 凸包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 单调栈维护凸包即可,用叉积判断: 维护上凸壳,然后把所有点的纵坐标翻转再求上凸壳即可, ...
随机推荐
- 获取CPU和内存的使用率
1.获取CPU的使用率 主要就是一个计算. int CUseRate::GetCPUUseRate() //获取CPU使用率 { ; FILETIME ftIdle, ftKernel, ftUser ...
- Ubuntu 无法获得锁
使用ubuntu安装pip 时,出现以下错误: E: 无法获得锁 /var/cache/apt/archives/lock – open (11 资源临时不可用) E: 无法锁定下载目录 解决方法: ...
- 快速切题 poj 1003 hangover 数学观察 难度:0
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103896 Accepted: 50542 Descr ...
- lseek使用说明
lseek使用说明 表头文件#include<sys/types.h>#include<unistd.h> 定义函数off_t lseek(int filde,off_t of ...
- php5.4.0以后加入trait实现代码复用【摘录】
在http://www.php.net/manual/zh/language.oop5.traits.php 查看了一下5.4.0提供的特性trait顺便做一个标记(总结): 首先要明确trait和类 ...
- vue 错误记录
1.错误信息: You may use special comments to disable some warnings.Use // eslint-disable-next-line to ign ...
- 今天开始写些随笔,就从Jplayer开始吧
今天才开始用Jplayer,可能有点落伍了,但是看到网上千篇一律的使用说明,开始决定把自己的使用心得分享一下,废话不多说,开始吧. Step1: 官网上有具体的搭建顺序,URL:http://www. ...
- linux下c语言源码编译
一.源码编译过程 源码 ---> 预处理 ---> 编译 ---> 汇编 ---> 链接 --->执行 我们可以把它分为三部分来完成: ./configure ...
- echarts-detail--柱状图
一:柱形图 1.Echarts-柱状图柱图宽度设置-----只需要设置series中的坐标系属性barWidth就可以 /** * 堆积柱状图 * @param xaxisdata x轴:标签(数组) ...
- oracle对三个列求sum
oracle数据库对test_table表的三个列count1,count2,count3求sum的两种sql,做个记录 第一种 select sum (case when count1 is not ...