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

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

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

竟然比原作者要快T T

  1. /**************************************************************
  2. Problem: 1670
  3. User: rausen
  4. Language: C++
  5. Result: Accepted
  6. Time:16 ms
  7. Memory:900 kb
  8. ****************************************************************/
  9.  
  10. #include <cstdio>
  11. #include <cmath>
  12. #include <algorithm>
  13.  
  14. #define points P
  15. using namespace std;
  16. typedef long long ll;
  17. const int N = ;
  18. int n, top;
  19. double ans;
  20. struct points{
  21. int x, y;
  22. }p[N], s[N];
  23.  
  24. inline ll operator * (const P a, const P b){
  25. return a.x * b.y - a.y * b.x;
  26. }
  27.  
  28. inline P operator - (const P a, const P b){
  29. P tmp;
  30. tmp.x = a.x - b.x, tmp.y = a.y - b.y;
  31. return tmp;
  32. }
  33.  
  34. inline ll Sqr(const ll x){
  35. return x * x;
  36. }
  37.  
  38. inline ll dis(const P a, const P b){
  39. return Sqr(a.x - b.x) + Sqr(a.y - b.y);
  40. }
  41.  
  42. inline bool operator < (const P a, const P b){
  43. ll tmp = (a - p[]) * (b - p[]);
  44. return tmp == ? dis(p[], a) < dis(p[], b) : tmp > ;
  45. }
  46.  
  47. inline int read(){
  48. int x = , sgn = ;
  49. char ch = getchar();
  50. while (ch < '' || ch > ''){
  51. if (ch == '-') sgn = -;
  52. ch = getchar();
  53. }
  54. while (ch >= '' && ch <= ''){
  55. x = x * + ch - '';
  56. ch = getchar();
  57. }
  58. return sgn * x;
  59. }
  60.  
  61. int work(){
  62. int k = ;
  63. for (int i = ; i <= n; ++i)
  64. if (p[i].y < p[k].y || (p[i].y == p[k].y && p[i].x < p[k].x)) k = i;
  65. swap(p[], p[k]);
  66. sort(p + , p + n + );
  67. top = , s[] = p[], s[] = p[];
  68. for (int i = ; i <= n; ++i){
  69. while ((s[top] - s[top - ]) * (p[i] - s[top]) <= ) --top;
  70. s[++top] = p[i];
  71. }
  72. s[top + ] = p[];
  73. for (int i = ; i <= top; ++i)
  74. ans += sqrt(dis(s[i], s[i + ]));
  75. }
  76.  
  77. int main(){
  78. n = read();
  79. for (int i = ; i <= n; ++i)
  80. p[i].x = read(), p[i].y = read();
  81. work();
  82. printf("%.2lf\n", ans);
  83. }

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. SxsTrace

    https://troubleshooter.xyz/wiki/fix-the-application-has-failed-to-start-because-the-side-by-side-con ...

  2. BZOJ2982: combination Lucas

    Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...

  3. MongoDB树形结构表示法

    http://docs.mongodb.org/manual/tutorial/model-tree-structures/ MongoDB五种树形结构表示法 第一种:父链接结构 db.categor ...

  4. NS3 一个小问题

    可能会在执行./waf 命令的时候遇到这个问题,比如我想编译 /home/wasdns/Documents/NS3/ns-3.17/scratch 目录下的一个文件:newnsthree.cpp 编译 ...

  5. UVa 821 网页跳跃(Floyd)

    https://vjudge.net/problem/UVA-821 题意:给出一个有向图,任意两点都可相互到达,求任意两点的最短距离的平均值. 思路:求两点的最短距离,用Floyd算法很方便,最后加 ...

  6. 【BZOJ】4012: [HNOI2015]开店

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4012 给出一个$n$个点的树,树上每一个点都有一个值$age$,每条边都有边权,每次查询一 ...

  7. SQL实现新增表,表名更改,列名更改,约束更改等

    --新建表: CREATE TABLE TABLENAME ( ID INT IDENTITY (1,1) PRIMARY KEY , NAME VARCHAR(50) DEFAULT 'HELLO' ...

  8. 【Robot Framework 项目实战 00】环境搭建

    前言 我们公司在推广RF这个框架做后端接口测试,力求让同事们能更快的完成服务端需求的自动化,作为主导者之一,决定分享一些经验,方便后来者. 我会从安装部署.Request.selenium.自定义框架 ...

  9. IdentityServer3零星笔记

    Scope 是什么?有哪几种类型?每种类型都怎么使用? StandardScopes.All是什么概念? 解释:在Scope的Claims属性里包含的所有声明(类型是ScopeClaim,它的name ...

  10. Java数组的定义和使用

    如果希望保存一组有相同类型的数据,可以使用数组. 数组的定义和内存分配 Java 中定义数组的语法有两种: type arrayName[]; type[] arrayName; type 为Java ...