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. 莫比乌斯反演--HDU模板题

    题意:http://acm.hdu.edu.cn/showproblem.php?pid=1695 直接上莫比乌斯模板. #include <bits/stdc++.h> using na ...

  2. PHP的四种运行方式

    一丶cgi协议模式 cgi模式通用网关接口(Common Gateway Interface),它允许web服务器通过特定的协议与应用程序通信,调用原理大概为:用户请求->Web服务器接收请求- ...

  3. Attribute自定义特性+Asp.net MVC中的filter详解

    转载自:http://blog.csdn.net/wangyy130/article/details/44241957 一.filter简介 在了解自定义特性前,先引入一个概念filter,它是MVC ...

  4. WinSockAPI多线程服务器

    运行效果: 程序: // TcpServer.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream&g ...

  5. Qt使用自带的windeployqt 查找生成exe 必需的库文件

    集成开发环境 QtCreator 目前生成图形界面程序 exe 大致可以分为两类:Qt Widgets Application  和 Qt Quick Application.下面分别介绍这两类exe ...

  6. 很low的四位验证码实现

    <html> <head> <meta charset="utf-8"> </head> <body> <inpu ...

  7. 微信小程序data-传参

    <view bindtap="change" data-index="{{index}}">哈哈</view> change(event ...

  8. 使用pycharm 编写代码 并在远程主机上运行

    一 要求 远程主机有python解释器 二 在菜单栏,File -> Settings… -> Project ×× -> Project Interpreter,点击右侧 Add按 ...

  9. gulp die('click').live('click' composer

    gulp  die('click').live('click' composer packagist.org https://getcomposer.org/ 下载后 php composer.pha ...

  10. vue常用知识点

    vue中图片路径写法 <img :src="avatorSrc" alt=""> <img :src="avatorSrc2&quo ...