HDU 1392 Surround the Trees 构造凸包
又是一道模板题
#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 构造凸包的更多相关文章
- HDU 1392 Surround the Trees(凸包入门)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 题解报告: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 ...
- HDU 1392 Surround the Trees(凸包)
题面 懒得粘贴了... 大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长. 题解 直接求出凸包,统计一遍答案即可 #include<iostream> #include< ...
- HDU 1392 Surround the Trees(凸包)题解
题意:给一堆二维的点,问你最少用多少距离能把这些点都围起来 思路: 凸包: 我们先找到所有点中最左下角的点p1,这个点绝对在凸包上.接下来对剩余点按照相对p1的角度升序排序,角度一样按距离升序排序.因 ...
- HDU - 1392 Surround the Trees (凸包)
Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...
- 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 ...
- hdu 1392 Surround the Trees 凸包模板
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees (凸包)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- BZOJ 2157 旅行
裸链剖. 这大概是我第一份两百行左右的代码吧. 然而我把题看错了233333333调了将近两天. #include<iostream> #include<cstdio> #in ...
- wx菜单栏
#include "MainFrame.h" BEGIN_EVENT_TABLE(MyFrame,wxFrame) EVT_MENU(wxID_FILE,MyFrame::OnMe ...
- Clusterware后台进程
Clusterware由若干进程组成,其中最重要的是CRSD,CSSD,EVMD 在Clusterware安装的最后阶段,会要求在每个节点执行root.sh脚本,这个脚本实际的作用就是在/etc/ ...
- 【UVa-514】铁轨——栈的学习
UVa514 Rails(铁轨) 题目:铁轨 题目链接: UVa514链接 题目描述: 某城市有一个火车站,有n节车厢从A方向驶入车站,按进站的顺序编号为1-n.你的任务是判断是否能让它们按照某种特定 ...
- Oracle 11g RAC oc4j/gsd Offline
Oracle 11g RAC中,发现oc4j以及gsd服务都处于offline状态,这是Oracle 11g RAC默认情形.即便如此,并不影响数据库的使用,因为 oc4j 是用于WLM 的一个资源, ...
- .net core 中的序列化和反序列化
学习博客:http://www.voidcn.com/blog/dujingjing1230/article/p-1204454.html
- 工具栏ToolStrip能触发焦点控件的Leave、Validating、DataError等事件以验证数据 z
public class ToolStripEx : ToolStrip { protected override void OnClick(EventArgs e) { base.OnClick(e ...
- Microsoft Office 2010 requires 的 MSXML 版本 6.10.1129.0 be 已安装在您计算机的安装"的基于 Windows 7 的计算机上安装 Office 2010 时出现错误消息
https://support.microsoft.com/zh-cn/kb/2290714
- jquery功能实现总结
最近一直在做.net这方面的,也学习了jquery一些东西,其中实现了自动关闭页面,json解析字符串,拼接字符串,for循环,函数调用,等一些功能,自己也学习了,也希望可以帮助大家,大家看后给提提意 ...
- js和jquery实现tab选项卡
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...