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 ...
随机推荐
- 安装CouchbaseClient的过程中提示 Error 1935.An error occurred during the installation of assembly;Error:-1603 fatal error during installation
安装过程中提示报错 点击确定后 安装程序会接着回滚,又提示报错如下 Error 1935的解决方法是下载一个微软的补丁. http://support.microsoft.com/de ...
- swift2.0 Cannot assign a value of type '[CFString]' to a value of type '[String]'
Cannot assign a value of type '[CFString]' to a value of type '[String]' 代码示例如下: picker.mediaTypes = ...
- LeetCode Binary Tree Maximum Path Sum 二叉树最大路径和(DFS)
题意:给一棵二叉树,要求找出任意两个节点(也可以只是一个点)的最大路径和,至少1个节点,返回路径和.(点权有负的.) 思路:DFS解决,返回值是,经过从某后代节点上来到当前节点且路径和最大的值.要注意 ...
- windows下mysql 数据库的导入导出
1.以.sql方式方式导入导出 http://www.360doc.com/content/11/0114/11/2905268_86441355.shtml 2.以.txt方式导入导出 http:/ ...
- unity, audio falloff
要达到声音随距离衰减的效果,需要使用3D音效,即把Spatial Blend设为1,然后再调节Min Distance和Max Distance(蓝色线框球体),并选择合适的Volume Rollof ...
- MongoDB数据库和集合的状态信息
查看数据库统计信息:db.stats() > use testswitched to db test> db.stats(){ "db" : " ...
- 基于jQuery的AJAX和JSON的实例
通过jQuery内置的AJAX功能,直接访问后台获得JSON格式的数据,然后通过jQuer把数据绑定到事先设计好的html模板上,直接在页面上显示. 我们先来看一下html模板: ...
- ipad iphone 开发的应用,加一个启动预览图片
如果你想在你的ipad,iphone应用启动是不显示黑屏幕,而是用一个图片代替的话,你只需要吧一张名为 Default.png 的图片加到项目里就行了. 很简单吧,新手们记得去这样美化下你的应用吗,很 ...
- XML序列化成对象
这个是和ALM上传测试结果结合使用的//把xml序列化成对象以及把对象序列化成xml using System; using System.Data; using System.Configurati ...
- spring BeanFactory概述
BeanFactory是Spring提供的两种容器类型之一,它是基础的IoC容器,并提供完整的IoC服务支持.如果没有指定,默认采用延迟初始化策略.只有当客户端对象需要访问容器中的某个受管对象的时候, ...