**链接:****传送门 **

题意:给出二维坐标轴上 n 个点,这 n 个点构成了一个城堡,国王想建一堵墙,城墙与城堡之间的距离总不小于一个数 L ,求城墙的最小长度,答案四舍五入

思路:城墙与城堡直线长度是相等的,当城堡出现拐角时,城墙必然会出现一段圆弧,这些圆弧最终会构成一个半径为 L 的圆,所以答案就是凸包的周长 + 圆的周长

balabala:

  1. 采用Jarvis步进法来求凸包,Jarvis步进法复杂度为O(nh),h为凸包顶点个数
  2. 采用Graham-Scan来求凸包,Graham - Scan 法复杂度为O(nlogn)

如有错误请一定指出!


Graham - Scan法:

/*************************************************************************
> File Name: hdu1348t2.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月07日 星期日 20时49分15秒
************************************************************************/ #include<bits/stdc++.h>
using namespace std; // Graham - Scan
// O(nlgn) #define PI 3.1415926535
const int maxn = 1010;
struct point{
double x,y;
}; bool cmp(point a,point b){
return (a.y<b.y || (a.y==b.y && a.x<b.x));
}
bool mult(point sp,point ep,point op){
return (sp.x-op.x)*(ep.y-op.y)>=(sp.y-op.y)*(ep.x-op.x);
}
point res[maxn];
int Graham(point pnt[],int n){
int i , len , k = 0 , top = 1;
sort(pnt,pnt+n,cmp);
if(n == 0) return 0; res[0] = pnt[0];
if(n == 1) return 1; res[1] = pnt[1];
if(n == 2) return 2; res[2] = pnt[2];
for(int i=2;i<n;i++){
while( top && mult( pnt[i] , res[top] , res[top-1] ))
top--;
res[++top] = pnt[i];
}
len = top; res[++top] = pnt[n-2];
for(i=n-3;i>=0;i--){
while( top!=len && mult( pnt[i] , res[top] , res[top-1] ))
top--;
res[++top] = pnt[i];
}
return top;
}
double point_dis(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
int main(){
int T , n , L , kase = 0;
point pi[maxn];
scanf("%d",&T);
while(T--){
if(kase > 0) printf("\n");
kase++;
scanf("%d%d",&n,&L);
for(int i=0;i<n;i++) scanf("%lf%lf",&pi[i].x,&pi[i].y);
int t = Graham(pi,n);
double ans = 2*PI*L;
for(int i=0;i<t;i++){
ans += point_dis( res[i] , res[ (i+1)%t ] );
}
printf("%.lf\n",ans);
}
return 0;
}

Jarvis步进法:

/*************************************************************************
> File Name: hdu1348.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月07日 星期日 18时55分57秒
************************************************************************/ #include<bits/stdc++.h>
using namespace std; #define PI 3.1415926535
const int maxn = 1010;
struct point{
double x,y;
}pi[maxn]; bool cmp(point a,point b){
return ( a.y<b.y || a.y==b.y && a.x<b.x);
} int n,L,ans[maxn],cnt,sta[maxn],tail;
// 检查是否严格左转,共线不算左转
bool CrossLeft(point p1,point p2,point p3){
return ((p3.x-p1.x)*(p2.y-p1.y) - (p2.x-p1.x)*(p3.y-p1.y)) < 0;
}
void Jarvis(){
tail = cnt = 0;
sort(pi,pi+n,cmp);
sta[tail++] = 0; sta[tail++] = 1;
for(int i=2;i<n;i++){
while(tail>1 && !CrossLeft( pi[ sta[tail-1] ] , pi[ sta[tail-2] ] , pi[i] ))
tail--;
sta[ tail++ ] = i;
}
for(int i=0;i<tail;i++) ans[cnt++] = sta[i];
tail = 0; sta[ tail++ ] = n-1; sta[ tail++ ] = n-2;
for(int i=n-3;i>=0;i--){
while(tail>1 && !CrossLeft( pi[ sta[tail-1] ] , pi[ sta[tail-2] ] , pi[i] ))
tail--;
sta[ tail++ ] = i;
}
for(int i=0;i<tail;i++) ans[cnt++] = sta[i];
}
double Point_dis(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
int main(){
int T , kase = 0;
scanf("%d",&T);
while(T--){
if(kase) printf("\n");
kase++;
scanf("%d%d",&n,&L);
for(int i=0;i<n;i++) scanf("%lf%lf",&pi[i].x,&pi[i].y);
Jarvis();
double re = 2*PI*L;
for(int i=0;i<cnt-1;i++){
re += Point_dis( pi[ans[i]] , pi[ans[i+1]] );
}
printf("%.0lf\n",re);
}
return 0;
}

HDU 1348 Wall ( 凸包周长 )的更多相关文章

  1. hdu 1348 Wall (凸包模板)

    /* 题意: 求得n个点的凸包.然后求与凸包相距l的外圈的周长. 答案为n点的凸包周长加上半径为L的圆的周长 */ # include <stdio.h> # include <ma ...

  2. hdu 1348 Wall (凸包)

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

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

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

  4. hdu 1348 (凸包求周长)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  5. hdu 1348 Wall(凸包模板题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. HDU 1348 Wall 【凸包】

    <题目链接> 题目大意: 给出二维坐标轴上 n 个点,这 n 个点构成了一个城堡,国王想建一堵墙,城墙与城堡之间的距离总不小于一个数 L ,求城墙的最小长度,答案四舍五入. 解题分析: 求 ...

  7. HDU 1348 Wall

    题解:计算凸包周长 #include <iostream> #include <cmath> #include <algorithm> const int size ...

  8. POJ 1113 || HDU 1348: wall(凸包问题)

    传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissio ...

  9. hdu 1348【凸包模板】

    #include<iostream> #include<iostream> #include<algorithm> #include<cmath> us ...

随机推荐

  1. [luogu3237 HNOI2014] 米特运输 (树形dp)

    传送门 Description 米特是D星球上一种非常神秘的物质,蕴含着巨大的能量.在以米特为主要能源的D星上,这种米特能源的运输和储存一直是一个大问题. D星上有N个城市,我们将其顺序编号为1到N, ...

  2. linux github 添加ssh

    1.本地生成key,  xxx 是github 的账号, 执行下面命令一路下一步 ssh-keygen -t rsa -C "xxx" 2.复制下面的public key 到git ...

  3. django rest-farme-work 的使用(1)

    Django REST框架是一个用于构建Web API的强大且灵活的工具包 您可能想要使用REST框架的一些原因: 可浏览性 身份认证 支持ORM和非ORM的序列化 良好的文档支持 安装初步 pip ...

  4. Qt QImage与OpenCV Mat转换

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51029382 应一个朋友的要求,整理总 ...

  5. 02springMVC理解DispatcherServlet

    DispatcherServlet的作用 DispatcherServlet在Web.xml中的配置 上下文关系 DispatcherServlet初始化顺序 DispatcherServlet中使用 ...

  6. C#基础概念 代码样例

    C# int与string一起操作时注意 1 int a1= 1; 2 string a2= "2"; 3 Console.WriteLine(a1+a2); 4 Console. ...

  7. BA-Delta知识点

    问题: DSM-RTR的网络负载能力是怎样的?每条总线带32个模块吗?MS/TP总线上的模块需要拨地址码吗?最大可以承载多少个点? 答:理论值是30,最佳性能是21个,一般情况25-28个 linkn ...

  8. vue v-for 渲染完成回调

    vue开发中等待vue渲染完成后加载数据的回调方法 Vue.nextTick(function () { alert("加载完成!"); }) 特别注意,如果使用ajax异步渲染的 ...

  9. Storm同时接收多个源(spout和bolt)

    参考: http://blog.csdn.net/nyistzp/article/details/51483779

  10. 技术总结--android篇(一)--MVC模式

    先介绍下MVC模式:MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显 ...