HDU 1392 Surround the Trees(凸包)
题面
懒得粘贴了。。。
大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长。
题解
直接求出凸包,统计一遍答案即可
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
#define MAX 10000
#define INF 1000000000
int n,top;
struct Node
{
	   int x,y;
}p[MAX],S[MAX];
inline int read()
{
	   int x=0,t=1;char ch=getchar();
	   while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	   if(ch=='-'){t=-1;ch=getchar();}
	   while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	   return x*t;
}
inline bool cmp(Node a,Node b)
{
	   double A=atan2((a.y-p[1].y),(a.x-p[1].x));
	   double B=atan2((b.y-p[1].y),(b.x-p[1].x));
	   if(A!=B)return A<B;
	   else    return a.x<b.x;
}
long long Cross(Node a,Node b,Node c)
{
	   return 1LL*(b.x-a.x)*(c.y-a.y)-1LL*(b.y-a.y)*(c.x-a.x);
}
void Get()
{
	   p[0]=(Node){INF,INF};int k;
	   for(int i=1;i<=n;++i)
	   	      if(p[0].y>p[i].y||(p[0].y==p[i].y&&p[i].x<p[0].x))
	   	       {p[0]=p[i];k=i;}
	   swap(p[k],p[1]);
	   sort(&p[2],&p[n+1],cmp);
	   S[0]=p[1],S[1]=p[2];top=1;
	   for(int i=3;i<=n;)
	   {
	   	      if(top&&Cross(S[top-1],p[i],S[top])>=0)top--;
	   	      else  S[++top]=p[i++];
	   }
}
inline double Dis(Node a,Node b)
{
	   return sqrt(1LL*(a.x-b.x)*(a.x-b.x)+1LL*(a.y-b.y)*(a.y-b.y));
}
inline void GetAns()
{
	   double Ans=0;
	   if(top==0)
	      Ans=0;
	   else
	   if(top==1)
	      Ans=Dis(S[0],S[1]);
	   else
	   {
		   S[++top]=S[0];
		   for(int i=0;i<top;++i)
		     Ans+=Dis(S[i],S[i+1]);
	   }
	   printf("%.2f\n",Ans);
}
int main()
{
	   while(233333)
	   {
	          n=read();
	          if(!n)break;
			  for(int i=1;i<=n;++i)
			     p[i]=(Node){read(),read()};
			  Get();
			  GetAns();
	   }
	   return 0;
}
												
											HDU 1392 Surround the Trees(凸包)的更多相关文章
- 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 ...
 - HDU 1392 Surround the Trees(凸包*计算几何)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
 - 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 ...
 - HDUJ  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
		
There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...
 
随机推荐
- shell编程之运算符(3)
			
declare声明变量类型 declare[+/-][选项]变量名 选项: - : 给变量设定类型属性 + : 取消变量的类型属性 -a : 将变量声明为数组型 -i : 将变量声明为整数型(inte ...
 - Netty基础点滴
			
编写一个应答服务器 编写一个应答服务器 写一个Netty服务器主要由两部分组成: 配置服务器功能,如线程.端口 实现服务器处理程序,它包含业务逻辑,决定当有一个请求连接或接收数据时该做什么 启动服务器 ...
 - 洛谷P1896 [SCOI2005]互不侵犯King【状压DP】
			
题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. 输入格式: 只有一行,包含两个数N,K ...
 - 基于jq的表单填充
			
//表单填充 formDataLoad: function (domId, obj) { for (var property in obj) { if (obj.hasOwnProperty(prop ...
 - Xen的虚拟化详解
			
最近在看Xen在2003年发表在sosp上的论文<Xen and the Art of Virtualization>,中途遇到一些不理解的技术点,在网络上查找相关资料,发现大多数人都只是 ...
 - 基于Jquery+Ajax+Json+存储过程 高效分页
			
在做后台开发中,都会有大量的列表展示,下面给大家给大家分享一套基于Jquery+Ajax+Json+存储过程高效分页列表,只需要传递几个参数即可.当然代码也有改进的地方,如果大家有更好的方法,愿留下宝 ...
 - spring 完成multipart数据上传
			
spring中多媒体文件的上传,通过配置 MultipartResolver 实现. MultipartResolver 的实现类有两个:一.StandardServletMultipartResol ...
 - java常用类————Date类
			
Date类在Java.util包中. 一.功能介绍:创建Date对象,获取时间,格式化输出的时间. 二.对象创建:1.使用Date类无参数的构造方法创建的对象可以获取本地时间.例如: Date now ...
 - postman模拟HttpPost请求的方法
			
开始想装postman的Google浏览器插件的,但是发现应用商店无法搜索,下载的拖进扩展也装不上... 于是找到了这个绿色版的Postman桌面程序!有需要的可以下载,点击下载:http://dow ...
 - WebApi 参数绑定方法
			
WebAPI 2参数绑定方法 简单类型参数 Example 1: Sending a simple parameter in the Url 01 02 03 04 05 06 07 08 09 ...