裸的凸包。。。(和旋转卡壳有什么关系吗。。。蒟蒻求教T T)

话说忘了怎么写了。。。(我以前都是先做上凸壳再做下凸壳的说)

于是看了下hzwer的写法,用了向量的点积,方便多了,于是果断学习(Orz)了!

竟然比原作者要快T T

 /**************************************************************
Problem: 1670
User: rausen
Language: C++
Result: Accepted
Time:16 ms
Memory:900 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <algorithm> #define points P
using namespace std;
typedef long long ll;
const int N = ;
int n, top;
double ans;
struct points{
int x, y;
}p[N], s[N]; inline ll operator * (const P a, const P b){
return a.x * b.y - a.y * b.x;
} inline P operator - (const P a, const P b){
P tmp;
tmp.x = a.x - b.x, tmp.y = a.y - b.y;
return tmp;
} inline ll Sqr(const ll x){
return x * x;
} inline ll dis(const P a, const P b){
return Sqr(a.x - b.x) + Sqr(a.y - b.y);
} inline bool operator < (const P a, const P b){
ll tmp = (a - p[]) * (b - p[]);
return tmp == ? dis(p[], a) < dis(p[], b) : tmp > ;
} inline int read(){
int x = , sgn = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-') sgn = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return sgn * x;
} int work(){
int k = ;
for (int i = ; i <= n; ++i)
if (p[i].y < p[k].y || (p[i].y == p[k].y && p[i].x < p[k].x)) k = i;
swap(p[], p[k]);
sort(p + , p + n + );
top = , s[] = p[], s[] = p[];
for (int i = ; i <= n; ++i){
while ((s[top] - s[top - ]) * (p[i] - s[top]) <= ) --top;
s[++top] = p[i];
}
s[top + ] = p[];
for (int i = ; i <= top; ++i)
ans += sqrt(dis(s[i], s[i + ]));
} int main(){
n = read();
for (int i = ; i <= n; ++i)
p[i].x = read(), p[i].y = read();
work();
printf("%.2lf\n", ans);
}

BZOJ1670 [Usaco2006 Oct]Building the Moat护城河的挖掘的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. [bzoj1670][Usaco2006 Oct]Building the Moat

    Description 为了防止口渴的食蚁兽进入他的农场,$Farmer John$决定在他的农场周围挖一条护城河.农场里一共有$N$股泉水,并且,护城河总是笔直地连接在河道上的相邻的两股泉水.护城河 ...

随机推荐

  1. 20145205武钰《网络对抗》web安全基础实践

    实验后问题回答 (1)SQL注入攻击原理,如何防御 攻击原理:SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意SQL命令的目的 防御手 ...

  2. 小测(noip2005的两道题) 2017.3.3

    过河 题目描述 Description 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把 ...

  3. List集合实现简易学生管理

    题目: 代码: package org.wlgzs; import java.util.ArrayList; import java.util.List; import java.util.Scann ...

  4. C#工程详解

    转:https://www.cnblogs.com/zhaoqingqing/p/5468072.html 前言 写这篇文章的目地是为了让更多的小伙伴对VS生成的工程有一个清晰的认识.在开发过程中,为 ...

  5. js 注意点

    1.var // 反例 myname = "global"; // 全局变量 function func() { alert(myname); // "undefined ...

  6. HDU1540 Tunnel Warfare(线段树区间维护&求最长连续区间)题解

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. Unity3D学习笔记(十二):2D模式和异步资源加载

    2D模式和3D模式区别:背景纯色,摄像机2D,没有深度轴 精灵图片设置 Normal map,法线贴图,更有立体感 Sprite (2D and UI),2D精灵贴图,有两种用途 1.当做UI贴图 2 ...

  8. OpenFlow protocol version 1.0 通信过程

    参考 李呈:[原创]OpenFlow通信流程解读 OpenFlow protocol version 1.0 通信过程 通信双方: OpenFlow控制器,OpenFlow交换机. 通信模块: Sec ...

  9. BZOJ 1010: [HNOI2008]玩具装箱toy(斜率优化dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1010 题意: 思路: 容易得到朴素的递归方程:$dp(i)=min(dp(i),dp(k)+(i-k ...

  10. Docker operation

    Docker 容器镜像删除 1.停止所有的container,这样才能够删除其中的images: docker stop $(docker ps -a -q) 如果想要删除所有container的话再 ...