思路:

凸包模板题。
注意n=1和n=2的情况。
当n=1时,不需要绳子。
当n=2时,绳子长度为两棵树之间距离。
当n≥e时,Graham求凸包即可。最后将凸包上的所有相邻点距离求和。

  1. #include<cmath>
  2. #include<cstdio>
  3. #include<cctype>
  4. #include<algorithm>
  5. inline int getint() {
  6. char ch;
  7. while(!isdigit(ch=getchar()));
  8. int x=ch^'';
  9. while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
  10. return x;
  11. }
  12. struct Point {
  13. int x,y;
  14. Point operator - (const Point &x) const {
  15. return (Point){this->x-x.x,this->y-x.y};
  16. }
  17. int operator * (const Point &x) const {
  18. return this->x*x.y-x.x*this->y;
  19. }
  20. };
  21. int dist2(const Point x,const Point y) {
  22. return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y);
  23. }
  24. double dist(const Point x,const Point y) {
  25. return sqrt(dist2(x,y));
  26. }
  27. const int N=;
  28. Point p[N];
  29. bool operator < (const Point &p1,const Point &p2) {
  30. int s=(p1-p[])*(p2-p[]);
  31. return s<||(!s&&(dist2(p1,p[]))>=dist2(p2,p[]));
  32. }
  33. bool judgeOnLeft(int p0,int p1,int p2) {
  34. double s=(p[p1]-p[p0])*(p[p2]-p[p0]);
  35. return s<||(!s&&(dist2(p[p1],p[p0]))>=dist2(p[p2],p[p0]));
  36. }
  37. inline void swap(Point &a,Point &b) {
  38. Point t;
  39. t=a;
  40. a=b;
  41. b=t;
  42. }
  43. int main() {
  44. int n;
  45. while(n=getint()) {
  46. if(n==) {
  47. puts("0.00");
  48. continue;
  49. }
  50. if(n==) {
  51. Point a,b;
  52. a.x=getint(),a.y=getint();
  53. b.x=getint(),b.y=getint();
  54. printf("%.2f\n",dist(a,b));
  55. continue;
  56. }
  57. int k=;
  58. for(int i=;i<n;i++) {
  59. p[i].x=getint(),p[i].y=getint();
  60. if((p[i].x<p[k].x)||((p[i].x==p[k].x)&&(p[i].y<p[k].y))) k=i;
  61. }
  62. swap(p[],p[k]);
  63. std::sort(&p[],&p[n]);
  64. p[n]=p[];
  65. int s[N],top=;
  66. s[]=;
  67. s[]=;
  68. for(int i=;i<=n;i++) {
  69. while(top&&judgeOnLeft(s[top-],i,s[top])) top--;
  70. s[++top]=i;
  71. }
  72. s[top]=s[];
  73. double ans=;
  74. for(int i=;i<=top;i++) {
  75. ans+=dist(p[s[i]],p[s[i-]]);
  76. }
  77. printf("%.2f\n",ans);
  78. }
  79. return ;
  80. }

[HDU1392]Surround the Trees的更多相关文章

  1. HDU-1392 Surround the Trees,凸包入门!

    Surround the Trees 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...

  2. ACM学习历程—HDU1392 Surround the Trees(计算几何)

    Description There are a lot of trees in an area. A peasant wants to buy a rope to surround all these ...

  3. hdu1392 Surround the Trees 凸包

    第一次做凸包,这道题要特殊考虑下,n=2时的情况,要除以二才行. 我是从最左边的点出发,每次取斜率最大的点,一直到最右边的点. 然后从最左边的点出发,每次取斜率最低的点,一直到最右边的点. #incl ...

  4. 【计算几何初步-凸包-Jarvis步进法。】【HDU1392】Surround the Trees

    [科普]什么是BestCoder?如何参加? Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  5. Surround the Trees[HDU1392]

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. HDU1392:Surround the Trees(凸包问题)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. Surround the Trees(凸包求周长)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. Surround the Trees(凸包)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. hdu 1392 Surround the Trees 凸包裸题

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

随机推荐

  1. 在全志平台调试博通的wifi驱动(类似ap6212)【转】

    转自:http://blog.csdn.net/fenzhi1988/article/details/44809779 调试驱动之前,首先先看看驱动代码,了解代码大致工作流程,再根据硬件配置驱动,比如 ...

  2. 移植BOA服务器到开发板

    移植BOA 服务器到GEC210 开发板 开发平台主机:VMWare--Ubuntu 10.04 LTS开发板:GEC210 / linux-2.6.35.7编译器:arm-linux-gcc-4.5 ...

  3. Sandcastle方法生成c#.net帮助类帮助文档chm

    Sandcastle方法生成c#.net帮助类帮助文档即chm后缀的文档,其实是通过C#文档注释生成的XML文件来生成帮助文档的.因此,第一步就是生成XML文档, 步骤1生成XML文档 1.打开VS- ...

  4. C 长字符串换行方法

    C中字符串有时候会出现很长的情况,如果不换行书写查看起来很不方便. 长字符串拆分成多行处理也是C规范的一部分. 方法1. 利用双引号" " ,将长字符串分成多个子串换行,C会自动无 ...

  5. jquery----用户密码验证

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. cf796d 树,bfs好题!

    绝对是好题,把所有警察局放入队列然后开始广搜,如果碰到了vis过的顶点,但是那条边没有访问过,那么这条边就可以删掉 另外广搜的vis标记是在入队时就打的,, #include<bits/stdc ...

  7. python3 + selenium 之窗口切换

    窗口切换 此代码来源学习后对淘宝操作实践记录: 以下代码在Chrome61和IE11上正常运行,Firefox5.7上运行存在一些问题须改进,应该是火狐不兼容差link_text部分和循环经常报错,在 ...

  8. 读取web.config和app.config配置文件

    app.config:       <add key="Password" value="123456"/> C#:   string TQpwd ...

  9. OSGI命令

    OSGi的一些支离破碎的知识 以下命令说明内容来自于Eclipse的OSGi框架Equinox. ---Controlling the OSGi framework---launch - start ...

  10. 使用SqlSugar 4.X的T4生成实体类

    <#@ template debug="false" hostspecific="true" language="C#" #> ...