裸的凸包。。。(和旋转卡壳有什么关系吗。。。蒟蒻求教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. 20145336 张子扬 《网络对抗技术》web基础

    20145336张子扬<网络对抗>Exp8 Web基础 实践内容 1.简单的web前端页面(HTML.CSS等) 2.简单的web后台数据处理(PHP) 3.Mysql数据库 4.一个简单 ...

  2. bzoj 2427 软件安装 - Tarjan - 树形动态规划

    题目描述 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi的和最大). 但是 ...

  3. sbt介绍与构建Scala项目

    一.sbt简介 sbt是类似ANT.MAVEN的构建工具,全称为Simple build tool,是Scala事实上的标准构建工具. 主要特性: 原生支持编译Scala代码和与诸多Scala测试框架 ...

  4. trust zone之我见【转】

    本文转载自:https://blog.csdn.net/hovan/article/details/42520879 老板交待任务,这个星期我都在研究trust zone的东东,之前有看过代码,但没有 ...

  5. 利用Qt开发跨平台APP

    本文将手把手教你如何在Windows环境下,使用Qt编译出安卓应用程序. Qt是一个优秀的跨平台开发工具.我们利用Qt可以很方便地将一次编写的应用,多次编译到不同平台上,如Windows.Linux. ...

  6. nginx配置二级域名

    我在我的服务器上面跑了两个node应用程序,分别一个端口2368跑的是ghost博客,一个端口8000跑的是我的demo程序.想要一级域名zhangruojun.com用来访问博客,二级域名demo. ...

  7. Ubuntu 下 su:authentication failure的解决办法

    Ubuntu下使用 su 切换到超级用户时候遇到下面的问题 su: Authentication failure 解决办法: $ sudo passwd root Enter new UNIX pas ...

  8. HDU 5963 朋友(找规律博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=5963 题意: 思路: 我们可以先只考虑单链,自己试几种案例就可以发现规律,只有与根相连的边为1时,只需要奇数次操 ...

  9. 对Tomcat启动或运行时,项目对jar包依赖路径的一些粗浅认知

    Tomcat在运行webapp项目的时候,需要各种依赖jar包.它会从2个地方去找这些包 1.Tomcat自己的lib目录中 2.webapp目录下,webapps\{项目}\WEB-INF\lib ...

  10. Linux——系统引导流程学习简单笔记

    开启电源: 固件 firmware(CMOS/BIOS) → POST 加电自检 对硬件就行检查 ↓ 自举程序 BootLoader(GRUB) → 载入内核 ↓ 载入内核 Kernel 1:驱动硬件 ...