1298 凸包周长

时间限制: 1 s

空间限制: 128000 KB

题目等级 : 钻石 Diamond

题目描述 Description

给出平面上n个点,求出这n个点形成的凸包的周长。

凸包的定义:能覆盖住这个n个点的最小凸多边形。

输入描述 Input Description

第一行一个整数n,接下来n行,每行两个整数x和y,表示一个点的坐标。

数据范围 1 <= n <= 100000

-10000<=x,y<=10000

输出描述 Output Description

一行一个实数,表示凸包周长,保留一位小数.

样例输入 Sample Input

5

0 0

2 2

0 2

2 0

1 1

样例输出 Sample Output

8.0

数据范围及提示 Data Size & Hint



分类标签 Tags

计算几何

/*
计算几何第二题留念flag.
Jarvis O(NM)(M为凸包上的点的个数)
从最下面的一坨点找一个最左边的点.
然后以向右为基准扫描.
用叉积判断两点的位置关系.
重复上述步骤即可.
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 100001
using namespace std;
int n,top;
double ans;
struct data{int x,y;}s[MAXN],a[MAXN];
bool cmp(const data &x,const data &y)
{
if(x.y!=y.y) return x.y<y.y;
return x.x<y.x;
}
bool chaji(const data &x,const data &y,const data &z)
{
return (y.x-x.x)*(z.y-x.y)>(z.x-x.x)*(y.y-x.y);
}
double slove(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d%d",&a[i].x,&a[i].y);
sort(a,a+n,cmp);
s[0]=a[0];s[1]=a[1];top=1;
for(int i=2;i<n;i++)
{
while(top&&!chaji(s[top],s[top-1],a[i])) top--;
s[++top]=a[i];
}
int l=top;
s[++top]=a[n-2];
for(int i=n-3;i>=0;i--)
{
while(top!=l&&!chaji(s[top],s[top-1],a[i])) top--;
s[++top]=a[i];
}
ans+=slove(s[0].x,s[0].y,s[top-1].x,s[top-1].y);
for(int i=0;i<top-1;i++)
ans+=slove(s[i].x,s[i].y,s[i+1].x,s[i+1].y);
printf("%.1lf",ans);
return 0;
}

Codevs 1298 凸包周长的更多相关文章

  1. HDU 1392 凸包模板题,求凸包周长

    1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...

  2. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  3. Wall---hdu1348(求凸包周长 模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 求凸包周长+2*PI*L: #include <stdio.h> #include ...

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

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

  5. HDU 1392 Surround the Trees (Graham求凸包周长)

    题目链接 题意 : 让你找出最小的凸包周长 . 思路 : 用Graham求出凸包,然后对每条边求长即可. Graham详解 #include <stdio.h> #include < ...

  6. poj 1113 凸包周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33888   Accepted: 11544 Descriptio ...

  7. LightOJ 1239 - Convex Fence 凸包周长

    LINK 题意:类似POJ的宫殿围墙那道,只不过这道题数据稍微强了一点,有共线的情况 思路:求凸包周长加一个圆周长 /** @Date : 2017-07-20 15:46:44 * @FileNam ...

  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 1348:Wall(计算几何,求凸包周长)

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

随机推荐

  1. [游戏复刻] 2048(2014. Android)

    等哪一天我有很多很多的时间再写吧...

  2. dede时间标签

    dedecms首页时间标签:1.12-27 样式([field:pubdate function='strftime("%m-%d",@me)'/]) 2.May 15, 2009 ...

  3. c c++各种类型的取值范围

    int类型的变量存储值从-2147483648到2147483647 //例子 #include <iostream> using namespace std; int main(void ...

  4. 监控提示message

    见文件 监控提示message.rar ---可作时时监控提示功能

  5. 计算机概论 64bit和32bit的CPU的不同

    32位(WOW32).64位(WOW64,x64)指的是两种不同的CPU架构. 32位的CPU能够在每个时钟周期传输32位数据,而64位的CPU能够在每个时钟周期传输64位数据. 32位系统可以访问2 ...

  6. select into from与insert into select区别

    创建一个table2  向table2中插入 table1中name为11的所有行(前提table2不存在) select * into table2 from table1 where name=‘ ...

  7. intellij IDE 破解 简单 License server 法

    http://idea.iteblog.com/key.php

  8. uni-app中picker组件的一个坑

    这里直接贴出代码 <view class="goods-info-add fl-sw"> <view>运费模板:</view> <view ...

  9. kubernetes 集群内部访问外部的数据库endpoint

    k8s访问集群外独立的服务最好的方式是采用Endpoint方式,以mysql服务为例: 创建mysql-service.yaml apiVersion: v1 kind: Service metada ...

  10. springboot-异步、发送邮件(一)

    pom.xml <!--邮件javax.mail--> <dependency> <groupId>org.springframework.boot</gro ...