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$股泉水,并且,护城河总是笔直地连接在河道上的相邻的两股泉水.护城河 ...
随机推荐
- SxsTrace
https://troubleshooter.xyz/wiki/fix-the-application-has-failed-to-start-because-the-side-by-side-con ...
- BZOJ2982: combination Lucas
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- MongoDB树形结构表示法
http://docs.mongodb.org/manual/tutorial/model-tree-structures/ MongoDB五种树形结构表示法 第一种:父链接结构 db.categor ...
- NS3 一个小问题
可能会在执行./waf 命令的时候遇到这个问题,比如我想编译 /home/wasdns/Documents/NS3/ns-3.17/scratch 目录下的一个文件:newnsthree.cpp 编译 ...
- UVa 821 网页跳跃(Floyd)
https://vjudge.net/problem/UVA-821 题意:给出一个有向图,任意两点都可相互到达,求任意两点的最短距离的平均值. 思路:求两点的最短距离,用Floyd算法很方便,最后加 ...
- 【BZOJ】4012: [HNOI2015]开店
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4012 给出一个$n$个点的树,树上每一个点都有一个值$age$,每条边都有边权,每次查询一 ...
- SQL实现新增表,表名更改,列名更改,约束更改等
--新建表: CREATE TABLE TABLENAME ( ID INT IDENTITY (1,1) PRIMARY KEY , NAME VARCHAR(50) DEFAULT 'HELLO' ...
- 【Robot Framework 项目实战 00】环境搭建
前言 我们公司在推广RF这个框架做后端接口测试,力求让同事们能更快的完成服务端需求的自动化,作为主导者之一,决定分享一些经验,方便后来者. 我会从安装部署.Request.selenium.自定义框架 ...
- IdentityServer3零星笔记
Scope 是什么?有哪几种类型?每种类型都怎么使用? StandardScopes.All是什么概念? 解释:在Scope的Claims属性里包含的所有声明(类型是ScopeClaim,它的name ...
- Java数组的定义和使用
如果希望保存一组有相同类型的数据,可以使用数组. 数组的定义和内存分配 Java 中定义数组的语法有两种: type arrayName[]; type[] arrayName; type 为Java ...