BZOJ1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
裸的凸包。。。(和旋转卡壳有什么关系吗。。。蒟蒻求教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护城河的挖掘的更多相关文章
- 【计算几何】【凸包】bzoj1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define ...
- 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护城河的挖掘_求凸包
BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包 Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场 ...
- 【BZOJ】1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
http://www.lydsy.com/JudgeOnline/problem.php?id=1670 裸打了凸包.. #include <cstdio> #include <cs ...
- 牛客假日团队赛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护城河的挖掘
Description 求凸包周长. Sol 凸包+计算几何. 这好像叫什么 Graham Scan 算法... 这个可以求凸包的周长,直径,面积. 选择一个基点,然后按极角排序,最后用一个栈一直维护 ...
- bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 用叉积判断.注意两端的平行于 y 轴的. #include<cstdio> ...
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘【凸包】
凸包模板 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> ...
- [bzoj1670][Usaco2006 Oct]Building the Moat
Description 为了防止口渴的食蚁兽进入他的农场,$Farmer John$决定在他的农场周围挖一条护城河.农场里一共有$N$股泉水,并且,护城河总是笔直地连接在河道上的相邻的两股泉水.护城河 ...
随机推荐
- 20145118 《Java程序设计》第6周学习总结
20145118 <Java程序设计>第6周学习总结 教材学习内容总结 1.数据依靠串流在目的地与来源地之间传输,无论来去如何,只要取得InputStream或OutputStream的实 ...
- ms08_067攻击实验
ms08_067攻击实验 ip地址 开启msfconsole 使用search ms08_067查看相关信息 使用 show payloads ,确定攻击载荷 选择playoad,并查看相关信息 设置 ...
- Splay简介
Splay树,又叫伸展树,可以实现快速分裂合并一个序列,几乎可以完成平衡树的所有操作.其中最重要的操作是将指定节点伸展到指定位置, 目录 节点定义 旋转操作 伸展操作 插入操作 删除操作 lower_ ...
- windows下启动某程序提示缺失**.dll文件的处理方法
一.背景: 1.os : windows7 64bit 旗舰版 2.启动ftp服务端软件时提示缺失mfc100.dll文件 以上情形亲测有效 二.修复 2.1 从https://cn.dll-file ...
- object Add(object Before, object After, object Count, object Type);
[表达式] .Add(Before, After, Count, Type) [表达式] 一个代表 Sheets 对象的变量. Before指定工作表的对象,新建的工作表将置于此工作表之前. Afte ...
- json封装数据,然后通过创造的标签调用
<ul class="list"> <li></li> <li></li> <li></li> ...
- POJ 2976 Dropping tests(分数规划)
http://poj.org/problem?id=2976 题意: 给出ai和bi,ai和bi是一一配对的,现在可以删除k对,使得的值最大. 思路: 分数规划题,可以参考<挑战程序竞赛> ...
- POJ 1681 Painter's Problem(高斯消元+枚举自由变元)
http://poj.org/problem?id=1681 题意:有一块只有黄白颜色的n*n的板子,每次刷一块格子时,上下左右都会改变颜色,求最少刷几次可以使得全部变成黄色. 思路: 这道题目也就是 ...
- node - web 服务器 、server 服务器
node 作为服务端 - 基本使用 1. web 服务器 web.html <!DOCTYPE html> <html> <head> <meta chars ...
- mvn编译
mvn clean install -pl com:boss -am -DskipTests