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

题意:给出二维坐标轴上 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. centos7把编译安装的服务通过systemctl管理

    nginx编译安装的目录是/usr/local/nginx nginx配置文件是/usr/local/nginx/conf/nginx.conf systemctl管理的服务文件在/usr/lib/s ...

  2. SurgingFunction

  3. 用Python图像处理

    前几天弄了下django的图片上传,上传之后还需要做些简单的处理,python中PIL模块就是专门用来做这个事情的. 于是照葫芦画瓢做了几个常用图片操作,在这里记录下,以便备用. 这里有个字体文件,大 ...

  4. 用chrony代替ntpd时间同步服务器

    Chrony是一个开源的自由软件,它能保持系统时钟与时钟服务器(NTP)同步,让时间保持精确. 它由两个程序组成:chronyd和chronyc. chronyd是一个后台运行的守护进程,用于调整内核 ...

  5. C#--文件操作的一些技巧

    Using的特点 Using 打开什么,就自动关闭什么,using中包含的其他类是否关闭,using是不管的 XML文档读取 重点:必须是标准的xml文档,否则会出错 string xmlxx = @ ...

  6. JavaScript替换字符串中最后一个字符

    1.问题背景 在一个输入框中,限制字符串长度为12位.利用键盘输入一个数字,会将字符串中最后一位替换,比方:111111111111.再输入一个3,会显示111111111113 2.详细实现 < ...

  7. 剑指Offer面试题33(java版):把数组排成最小的数

    题目:输入一个正整数数组.把数组里面全部的数字拼接排成一个数,打印能拼接出的全部数字中的一个.比如输入数组{3,32.321}.则打印出这3个数字能排成的最小数字321323. 这个题目最直接的做法应 ...

  8. 彻底禁用resource manager

    禁用resource manager 由于发现系统的一个等待事件:resmgr:cpu quantum.这是由于resource manager的原因.看来resource manager 的bug还 ...

  9. [学习笔记—Objective-C]《Objective-C-基础教程 第2版》第十一章 属性

    11.1 使用属性值 @property float rainHandling; //表明此类具有float类型的属性,其名称为rainHandling 注意:属性的名称不必与实例变量名称同样. @s ...

  10. HDU 4912 lca贪心

    Paths on the tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...