就是求凸包的周长加以l为半径的圆周长,证明略

由于之前写过叉积,所以graham扫描算法不是很难理解

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct point{
double x,y;
};
point p[N],s[N];
int top,n;
double dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool comp(point a,point b)
{
int te=dir(p[],a,b);
if(te<)return ;
if(te==&&dis(p[],a)<dis(p[],b))return ;
return ;
}
void graham()
{
int pos,minx,miny;
minx=miny=inf;
for(int i=;i<n;i++)
{
if(p[i].x<minx||(p[i].x==minx&&p[i].y<miny))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,comp);
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
top=;
for(int i=;i<=n;i++)
{
while(dir(s[top-],s[top],p[i])>=&&top>=)top--;
s[++top]=p[i];
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int l;
cin>>n>>l;
for(int i=;i<n;i++)cin>>p[i].x>>p[i].y;
graham();
double ans=*pi*l;
for(int i=;i<top;i++)
{
// cout<<s[i].x<<" "<<s[i].y<<endl;
if(i==top-)ans+=dis(s[i],s[]);
else ans+=dis(s[i],s[i+]);
}
cout<<(int)(ans+0.5)<<endl;
return ;
}
/*
4 3
0 0
1 0
0 1
1 1
*/

poj1113凸包的更多相关文章

  1. poj1113 凸包

    result=对所有点凸包周长+pi*2*L WA了一次,被Pi的精度坑了 以后注意Pi尽可能搞精确一点.Pi=3.14还是不够用 Code: #include<vector> #incl ...

  2. POJ 1113 - Wall 凸包

    此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...

  3. [POJ1113&POJ1696]凸包卷包裹算法和Graham扫描法应用各一例

    凸包的算法比较形象好理解 代码写起来也比较短 所以考前看一遍应该就没什么问题了..>_< POJ1113 刚开始并没有理解为什么要用凸包,心想如果贴着城堡走不是更好吗? 突然发现题目中有要 ...

  4. POJ1113 Wall —— 凸包

    题目链接:https://vjudge.net/problem/POJ-1113 Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  5. POJ-1113 Wall 计算几何 求凸包

    题目链接:https://cn.vjudge.net/problem/POJ-1113 题意 给一些点,求一个能够包围所有点且每个点到边界的距离不下于L的周长最小图形的周长 思路 求得凸包的周长,再加 ...

  6. (模板)poj1113(graham扫描法求凸包)

    题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是kuangbin的. AC code ...

  7. POJ1113:Wall (凸包算法学习)

    题意: 给你一个由n个点构成的多边形城堡(看成二维),按顺序给你n个点,相邻两个点相连. 让你围着这个多边形城堡建一个围墙,城堡任意一点到围墙的距离要求大于等于L,让你求这个围墙的最小周长(看成二维平 ...

  8. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  9. 【POJ1113】Wall(凸包)

    [题目] Description Once upon a time there was a greedy King who ordered his chief Architect to build a ...

随机推荐

  1. 虚拟机——安装虚拟机时,提示intel VT-x处于禁用状态

    1.联想Lenovo扬天T4900C-00安转虚拟机提示: 按F12进入bios模式,修改Intel VT-x为启用,BIOS中依次选择:Advanced(高级)——CPU Configuration ...

  2. WSDL(WebService描述语言)文件介绍

    一.WSDL 1.WSDL 文档的组成部分 <portType>:web service 执行的操作 <message>:web service 使用的消息 <types ...

  3. vue Element-ui 表格自带筛选框自定义高度

    el-table中可以在一行的某列进行筛选,代码如下: <el-table-column prop="classOfTest" class="test" ...

  4. JDK环境变量配置目录jre,jvm

    类路径 :CLASSPATH= .;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tools.jar   JDK的路径:JAVA_HOME = C:/Program F ...

  5. hdu6206 Apple

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Oth ...

  6. 论文笔记:Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift

    ICML, 2015 S. Ioffe and C. Szegedy 解决什么问题(What) 分布不一致导致训练慢:每一层的分布会受到前层的影响,当前层分布发生变化时,后层网络需要去适应这个分布,训 ...

  7. win 7 64 安装 MondgoDB 3.4

    https://jingyan.baidu.com/article/f3e34a12ac10cef5eb653583.html mongod --dbpath "D:\Program Fil ...

  8. centos配置jdk的环境变量

    1.首先呢,centos下的JDK环境配置分两种情况,一直是root用户级别的jdk配置,另一种是其他用户组级别的配置.这里讲解的是root用户级别的配置. 我们已经下载解压好了jdk的目录.如下 2 ...

  9. linux 虚拟机设置好固定ip 修改了 dns 网络需要设置成桥接模式

    linux  虚拟机设置好固定ip 修改了 dns  网络需要设置成桥接模式  可以修复网络连接(浏览器返回 server not  found)

  10. 【Python】__slots__ 、@property、多重继承、定制类、枚举类、元类

    __slots__ @property 多重继承 定制类 枚举类 元类 [使用__slots__] 1.动态语言的一个特点就是允许给实例绑定任意的方法和变量,而静态语言(例如Java)必须事先将属性方 ...