又是一道模板题

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm> using namespace std; struct P
{
int x,y;
double angle;
} p[50010]; bool cmp(P p1,P p2)
{
return p1.angle > p2.angle;
} double calangle(P p,P t)
{
return ((t.x-p.x)*(t.x-p.x) + 1 - (t.x-p.x-1)*(t.x-p.x-1))/(2*sqrt((t.x-p.x)*(t.x-p.x) + (t.y-p.y)*(t.y-p.y)));
} P sp[50010]; bool judgesite(P p1,P p2, P p)
{
P l1,l2;
l1.x = p2.x - p1.x;
l1.y = p2.y - p1.y; l2.x = p.x - p1.x;
l2.y = p.y - p1.y; return (l1.x*l2.y - l1.y*l2.x) > 0 ? true : false ;
} double callen(P p1,P p2)
{
return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) );
} int main()
{
int n,i; int top; double MinLen; while(scanf("%d",&n) && n)
{ top = 0; for(i = 1; i <= n; ++i)
{
scanf("%d %d",&p[i].x,&p[i].y);
} P temp; for(temp = p[1],i = 2; i <= n; ++i)
{
if(temp.y > p[i].y)
{
temp = p[i];
}
else if(temp.y == p[i].y && temp.x > p[i].x)
{
temp = p[i];
}
} for(i = 1; i <= n; ++i)
{
if(temp.x != p[i].x || temp.y != p[i].y)
{
p[i].angle = calangle(temp,p[i]);
}
else p[i].angle = -2;
} sort(p+1,p+n+1,cmp); sp[top++] = p[n];
sp[top++] = p[1]; for(i = 2; i <= n;)
{
if(judgesite(sp[top-2],sp[top-1],p[i]))
{
sp[top++] = p[i];
++i;
}
else top--;
} top--;//最后一个点重复了 MinLen = callen(sp[top-1],sp[0]); for(i = 1; i < top; ++i)
{
MinLen += callen(sp[i-1],sp[i]);
} printf("%.2lf\n",MinLen);
}
return 0;
}

HDU 1392 Surround the Trees 构造凸包的更多相关文章

  1. HDU 1392 Surround the Trees(凸包入门)

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

  2. 题解报告:hdu 1392 Surround the Trees(凸包入门)

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

  3. HDU 1392 Surround the Trees(凸包)

    题面 懒得粘贴了... 大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长. 题解 直接求出凸包,统计一遍答案即可 #include<iostream> #include< ...

  4. HDU 1392 Surround the Trees(凸包)题解

    题意:给一堆二维的点,问你最少用多少距离能把这些点都围起来 思路: 凸包: 我们先找到所有点中最左下角的点p1,这个点绝对在凸包上.接下来对剩余点按照相对p1的角度升序排序,角度一样按距离升序排序.因 ...

  5. HDU - 1392 Surround the Trees (凸包)

    Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

  6. HDU 1392 Surround the Trees (凸包周长)

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

  7. hdu 1392 Surround the Trees 凸包模板

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

  8. hdu 1392: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. Windows下PhpStorm结合WAMP开发Phalcon应用的配置

    最近要利用Phalcon框架开发PHP应用,因为以前基本没接触过PHP更没用过PHP框架,结果整环境整IDE配置什么的花了好长时间 学习慕课网上的PHP入门教程安装了WAMP(windows+apac ...

  2. USACO 2013 Nov Silver Pogo-Cow

    最近因为闲的蛋疼(停课了),所以开始做一些 USACO 的银组题.被完虐啊 TAT 貌似 Pogo-Cow 这题是 2013 Nov Silver 唯一一道可说的题目? Pogo-Cow Descri ...

  3. Mysql 不同版本 说明

    Mysql 的官网下载地址: http://dev.mysql.com/downloads/ 在这个下载界面会有几个版本的选择. 1. MySQL Community Server 社区版本,免费,但 ...

  4. C#操作Excel,对Sheet插入次序的控制 (有待完善)

    C#对Excel文件的操作,插入工作表(Worksheet)的方法是 Workbook.Worksheets.Add().通常情况下,我们在EXCEL的工作薄中,使用菜单操作:插入一个新的工作表,那么 ...

  5. MySQL定期分析检查与优化表

    定期分析表   ANALYZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name [, tbl_name]   本语句用于分析和存储表的关键字分布.在分析期间,使 ...

  6. UITableViewCell 自定义绘制 性能高

    // //  FoodListTableViewCellB.m //  BabyFood // //  Created by zhuang chaoxiao on 16/3/7. //  Copyri ...

  7. Jersey搭建Restful服务器 on Ubuntu

    自己试着在Ubuntu上搭建一个 1.首先安装eclipse和tomcat sudo apt-get install eclipse tomcat7 -y 2.把tomcat的group assign ...

  8. NewtonPrincipia_物体的运动_求向心力

    NewtonPrincipia_物体的运动_求向心力 让我们看一下十七世纪的被苹果砸中的艾萨克,是怎样推导出向心力公式的 在现在的观点看来,其中涉及到的很多没有符号表示的微分量.下面的内容只是叙述了推 ...

  9. 大数据处理-bitmap是个神马东西

    1. Bit Map算法简介 所谓的Bit-map就是用一个bit位来标记某个元素对应的Value, 而Key即是该元素.由于采用了Bit为单位来存储数据,因此在存储空间方面,可以大大节省. 2. B ...

  10. MATLAB 通过二进制读写文件

    这几天在做信息隐藏方面的应用,在读写文本文件时耗费许久,故特别的上网学习一二,这里给出一常用读写,其他的都类似. 很多时候,我们都要将一个.txt以二进制方式读出来,操作后在恢复成.txt文本. ma ...