题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l

题解:因为两点间的直线一定比折线短,所以这样做

先使用所有点求得一个凸包,接着凸包每条边外移l长度,再在每相邻两条线间画一个半径为l的圆弧(想一想为什么)

因为凸包上每个点与平移后对应点相连会垂直于凸包对应的边,所有圆弧的每个角与对应多边形的内角互补

又因为多边形外角和为360度,所有可以看做凸包多加一个半径为l的圆

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1E-8
/*注意可能会有输出-0.000*/
#define sgn(x) (x<-eps? -1 :x<eps? 0:1)//x为两个浮点数差的比较,注意返回整型
#define cvs(x) (x > 0.0 ? x+eps : x-eps)//浮点数转化
#define zero(x) (((x)>0?(x):-(x))<eps)//判断是否等于0
#define mul(a,b) (a<<b)
#define dir(a,b) (a>>b)
typedef long long ll;
typedef unsigned long long ull;
const int Inf=<<;
const ll INF=1ll<<;
const double Pi=acos(-1.0);
const int Mod=1e9+;
const int Max=;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {};
inline int read()
{
scanf("%lf%lf",&x,&y);
}
inline Point operator-(const Point& a)const
{
return Point(x-a.x,y-a.y);
}
inline bool operator<(const Point& a)const
{
return sgn(x-a.x)<||(zero(x-a.x)&&sgn(y-a.y)<);
}
inline bool operator==(const Point& a)const
{
return zero(a.x-x)&&zero(a.y-y);
}
inline bool operator!=(const Point& a)const
{
return !(zero(a.x-x)&&zero(a.y-y));
}
};
typedef Point Vector;
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.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));
}
int ConvexHull(Point* p,int n,Point* convex)
{
sort(p,p+n);
int m=;
for(int i=; i<n; ++i)
if(p[i]!=p[m-])
p[m++]=p[i];
n=m;
m=;
for(int i=; i<n; ++i)
{
while(m>&&Cross(convex[m-]-convex[m-],p[i]-convex[m-])<)
m--;
convex[m++]=p[i];
}
int k=m;
for(int i=n-; i>=; --i)
{
while(m>k&&Cross(convex[m-]-convex[m-],p[i]-convex[m-])<)
m--;
convex[m++]=p[i];
}
if(n>)
m--;
return m;
}
Point convex[Max],wall[Max];
double Solve(int n,double l)
{
double perimeter=;
int m=ConvexHull(wall,n,convex);
for(int i=; i<=m; ++i)
{
perimeter+=Dis(convex[i-],convex[i%m]);
}
return perimeter+l*Pi*;
}
int main()
{
int t,n;
double l;
scanf("%d",&t);
while(t--)
{
scanf("%d %lf",&n,&l);
for(int i=; i<n; ++i)
{
wall[i].read();
}
printf("%.0f\n",Solve(n,l));
if(t)
printf("\n");
}
return ;
}

UVALive 2453 Wall (凸包)的更多相关文章

  1. hdu 1348 Wall (凸包)

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

  2. POJ 1113 Wall 凸包求周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26286   Accepted: 8760 Description ...

  3. POJ1113 Wall —— 凸包

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

  4. POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)

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

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

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

  6. POJ 1113 - Wall 凸包

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

  7. Wall(凸包POJ 1113)

    Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32360 Accepted: 10969 Description On ...

  8. POJ1113 Wall 凸包

    题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度. 题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题. #inc ...

  9. HDU1348 Wall 凸包

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1348 题意:给出一个凸包,求出与凸包距离 L的外圈周长 凸包模板题,练练Andrew算法求出凸包周长再 ...

随机推荐

  1. [asp.net core]定义Tag Helpers

    原文地址 https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/authoring Getting started wi ...

  2. 【04-10】java中的路径

    java中的路径 System.getProperty("user.dir")  获取工程的绝对路径 Class.class.getClass().getResource(&quo ...

  3. HashTable初次体验

    用惯了数组.ArryList,初次接触到HashTable.Dictionary这种字典储存对于我来说简直就是高大上. 1.到底什么是HashTable HashTable就是哈希表,和数组一样,是一 ...

  4. 5 Hbase

    # 大纲: * 认识 HBase * HBase 架构 * HBase读写流程   定义: *  HBase是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用Hbase 技术可在廉价PC S ...

  5. Eclipse 中文的设置

    步骤如下:一.下载:在Eclipse官网下载相应版本的中文包. 二.中文包安装:1.解压中文语言包中的两个文件夹至Eclipse文件夹的dropins文件夹中.(目录不要放错)2.安装:方法一:使用命 ...

  6. android-获得".apk"文件的相关信息。包名、版本号等等

    String filePath = "/sdcard/feijiedemo.apk"; PackageManager packageManager = getPackageMana ...

  7. android中xml tools属性详解

    第一部分 安卓开发中,在写布局代码的时候,ide可以看到布局的预览效果. 但是有些效果则必须在运行之后才能看见,比如这种情况:TextView在xml中没有设置任何字符,而是在activity中设置了 ...

  8. Activity系列讲解---数据传递

    在Android中,不同的Activity实例可能运行在一个进程中,也可能运行在不同的进程中.因此需要一种特别的机制帮助我们在Activity之间传递消息.Android中通过Intent对象来表示一 ...

  9. MySQL主从同步

    脚本 [root@test scripts]# cat ss.sh #!/bin/bash . /etc/init.d/functions MYUSER=root MYPASS=c565f972 SO ...

  10. gnu coreutils-8.25 for win32 static - Beta

    gnu.win32-coreutils-8.25.7z 2.7 Mb bc-1.06.tar.gz coreutils-8.25.tar.xz diffutils-3.5.tar.xz gawk-4. ...