题目链接

题意 : 让你找出最小的凸包周长 。

思路 : 用Graham求出凸包,然后对每条边求长即可。

Graham详解

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm> using namespace std ; struct point
{
int x,y ;
}p[],p1[];
int n ; double dis(point a,point b)
{
return sqrt(double((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))) ;
}
double cross(point a,point b,point c)
{
return (a.x-c.x)*(b.y-c.y) - (a.y-c.y)*(b.x-c.x) ;
}
bool cmp(point a,point b)
{
if(cross(a,b,p[]) > || cross(a,b,p[]) == && dis(a,p[]) < dis(b,p[]))
return true ;
return false ;
}
void Graham()
{
int cnt;
sort(p+,p+n,cmp) ;
p[n] = p[] ;
p1[] = p[] ;
p1[] = p[] ;
cnt = ;
for(int i = ; i <= n ; i++)
{
while(cnt >= && cross(p1[cnt-],p1[cnt],p[i]) <= ) cnt -- ;
p1[ ++cnt] = p[i] ;
}
double sum = 0.0 ;
for(int i = ; i < cnt ; i++)
{
sum += dis(p1[i],p1[i+]) ;
//printf("*%.2lf*\n",sum) ;
}
printf("%.2lf\n",sum) ;
}
int main()
{
while(~scanf("%d",&n) && n)
{
int pos = ;
for(int i = ; i < n ; i++)
{
scanf("%d %d",&p[i].x,&p[i].y) ;
if(p[pos].y > p[i].y || (p[pos].y == p[i].y && p[i].x < p[pos].x))
pos = i ;
}
if(n == ) {puts("0.00");continue ;}
if(n == )
{
printf("%.2lf\n",dis(p[],p[])) ;
continue ;
}
swap(p[pos],p[]) ;
//printf("%d %d\n",p[0].x,p[0].y) ;
Graham() ;
}
return ;
}

HDU 1392 Surround the Trees (Graham求凸包周长)的更多相关文章

  1. HDU 1392 Surround the Trees(几何 凸包模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1392 题目大意: 二维平面给定n个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...

  2. hdu 1392:Surround the Trees(计算几何,求凸包周长)

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

  3. 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 ...

  4. HDU 1392 Surround the Trees(凸包*计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...

  5. hdu 1348:Wall(计算几何,求凸包周长)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. POJ 1113 Wall(Graham求凸包周长)

    题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...

  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:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

随机推荐

  1. Android--获取使用的总流量和每个App的上传、下载的流量

    获得每个App的上传.下载的流量. 思路就是获取到我们手机上的所有app,再获得app里面使用的权限,如果app有网络权限,就显示出来. 代码很简单,代码里面也有比较详细的注释,下面直接上代码 布局文 ...

  2. Android--启动系统的剪切图像功能并返回结果

    直接上代码: //启动裁剪图片 private void cropPhotoUri(Uri uri){ Intent intent = new Intent("com.android.cam ...

  3. JavaScript高级程序设计之Date类型

    ECMAScript 中的 Date 类型是在早期 Java 的 java.util.Date 类基础上构建的. Date 类型使用自 UTC (国际协调时间)1970年1月1日午夜(零时)开始经过的 ...

  4. c++基础(三):多态

    virtual:虚函数.C++通过虚函数实现多态."无论发送消息的对象属于什么类,它们均发送具有同一形式的消息,对消息的处理方式可能随接手消息的对象而变"的处理方式被称为多态性.& ...

  5. iOS学习之UIScrollView

    一.UIScrollView的创建和常用属性      1.UIScrollView概述 UIScrollView是UIView的子类. UIScrollView作为所有滚动视图的基类. UIScro ...

  6. [转]SOLID开发原则-面向对象

    S.O.L.I.D是面向对象设计和编程(OOD&OOP)中几个重要编码原则(Programming Priciple)的首字母缩写. SRP The Single Responsibility ...

  7. 42.JTAG接口使用注意

    无论是客户反馈,还是自己亲身经历,USB-Blaster不能下载配置FPGA的情况时有出现.究其原因,大致有如下几条: 1. FPGA器件上的JTAG相关引脚出现故障: 2. USB-Blaster坏 ...

  8. homework-03 扑街。。

    1.思路 我的思路是利用进程间通信间来实现题目要求. 第一次打开的程序与第二次打开的程序并不是同一个进程,故需要进程间通信来是传递信息. windows下进程间通信的方式有很多,如文件映射.共享内存. ...

  9. Introduction to Haskell

    "I know why you're here. ...why you hardly sleep, why night after night, you sit by your comput ...

  10. Oracle无法drop用户,提示有连接不能删除时

    百度了一下,这个可以行得通 select username,sid,serial# from v$session alter system kill SESSION '133,169' ; drop ...