Convex Fence

I have a land consisting of n trees. Since the trees are favorites to cows, I have a big problem saving them. So, I have planned to make a fence around the trees. I want the fence to be convex (curves are allowed) and the minimum distance from any tree to the fence is at least d units. And definitely I want a single big fence that covers all trees.

You are given all the information of the trees, to be specific, the land is shown as a 2D plane and the trees are plotted as 2D points. You have to find the perimeter of the fence that I need to create as described above. And you have to minimize the perimeter.

One tree, a circular fence is needed           Two trees, the fence is shown

Input

Input starts with an integer T (≤ 10), denoting the number of test cases.

Each case starts with a line containing two integers n (1 ≤ n ≤ 50000), d (1 ≤ d ≤ 1000). Each of the next lines contains two integers xi yi (-108 ≤ xi, yi ≤ 108) denoting a position of a tree. You can assume that all the positions are distinct.

Output

For each case, print the case number and the minimum possible perimeter of the fence. Errors less than 10-3 will be ignored.

Sample Input

3

1 2

0 0

2 1

0 -1

0 2

3 5

0 0

5 0

0 5

Sample Output

Case 1: 12.566370614

Case 2: 12.2831853

Case 3: 48.4869943478

Hint

Dataset is huge, use faster i/o methods.

题目就是说,给定几个点,要用围栏围住所有点,且围栏与每个点的距离不小于D.

样例太水,再举几个例子:

多画几个图,你很快就会发现,所求答案就是原图凸包的周长+以D为半径的园的周长,水一水就过了.

 #include<cstdio>
 #include<cstring>
 #include<cmath>
 #include<algorithm>
 #include<iostream>
 #define LL long long
 #define PI (acos(-1.0))
 using namespace std;
 int n,top; double R;
 ],ch[];
 point operator - (point u,point v){point ret; ret.x=u.x-v.x,ret.y=u.y-v.y; return ret;}
 double dis(point u,point v){return sqrt((u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y));}
 LL cross(point u,point v){return u.x*v.y-v.x*u.y;}
 inline int read(){
     ,f=; char ch=getchar();
     '){if (ch=='-') f=-f; ch=getchar();}
     +ch-',ch=getchar();
     return x*f;
 }
 bool cmp(const point &u,const point &v){
     ],v-a[])>||cross(u-a[],v-a[])==&&dis(u,a[])<dis(v,a[]);
 }
 void Out_(){
     ;
     ){
         ; i<top; i++) ans+=dis(ch[i],ch[i+]);
         ans+=dis(ch[top],ch[]);
     }
     ans+=PI*R*;
     printf("%.7lf\n",ans);
 }
 void Graham(){
     ;
     ; i<=n; i++) if (a[i].y<a[now].y||a[i].y==a[now].y&&a[i].x<a[now].x) now=i;
     swap(a[now],a[]);
     sort(a+,a++n,cmp);
     ch[]=a[],ch[]=a[],ch[]=a[],top=;
     ; i<=n; i++){
         ],ch[top]-ch[top-])>) top--;
         ch[++top]=a[i];
     }
 }
 int main(){
     ; Ts<=T; Ts++){
         scanf(,,sizeof ch);
         ; i<=n; i++) a[i].x=read(),a[i].y=read();
         printf("Case %d: ",Ts);
         Graham(),Out_();
     }
     ;
 }

Convex Fence的更多相关文章

  1. LightOJ 1239 - Convex Fence 凸包周长

    LINK 题意:类似POJ的宫殿围墙那道,只不过这道题数据稍微强了一点,有共线的情况 思路:求凸包周长加一个圆周长 /** @Date : 2017-07-20 15:46:44 * @FileNam ...

  2. [LeetCode] Erect the Fence 竖立栅栏

    There are some trees, where each tree is represented by (x,y) coordinate in a two-dimensional garden ...

  3. [LeetCode] Convex Polygon 凸多边形

    Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...

  4. [LeetCode] Paint Fence 粉刷篱笆

    There is a fence with n posts, each post can be painted with one of the k colors. You have to paint ...

  5. poj 3253 Fence Repair

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 42979   Accepted: 13999 De ...

  6. Leetcode: Convex Polygon

    Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...

  7. CF 484E - Sign on Fence

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  8. poj3253 Fence Repair

    http://poj.org/problem?id=3253 Farmer John wants to repair a small length of the fence around the pa ...

  9. low-rank 的相关求解方法 (CODE) Low-Rank Matrix Recovery and Completion via Convex Optimization

    (CODE) Low-Rank Matrix Recovery and Completion via Convex Optimization 这个是来自http://blog.sina.com.cn/ ...

随机推荐

  1. FZU 2150 Fire Game(点火游戏)

    FZU 2150 Fire Game(点火游戏) Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description - 题目描述 ...

  2. 文档对象模型DOM

    文档对象模型 DOM 1 DOM概述 1.1 什么是DOM 文档对象模型 Document Object Model 提供给用户操作document obj 的标准接口 文档对象模型 是表示和操作 H ...

  3. Perl中命令行参数以及打开管道文件

    打开管道文件   Linux提供了管道机制,可以方便应用程序之间的数据传递.在Perl中,扣开和使用管道可采用如下形式的open函数:   open(Filehandle,”丨 CMD”);   其中 ...

  4. hdu 4349 Xiao Ming's Hope 规律

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. JavaEE编程实验 实验1 Java常用工具类编程(未完成)

    1.使用String类分割split将字符串“Solutions to selected exercises can be found in the electronic document The T ...

  6. django 消息框架 message

    在网页应用中,我们经常需要在处理完表单或其它类型的用户输入后,显示一个通知信息给用户. 对于这个需求,Django提供了基于Cookie或者会话的消息框架messages,无论是匿名用户还是认证的用户 ...

  7. 利用vue-cli3快速搭建vue项目详细过程

    一.介绍 Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统.有三个组件: CLI:@vue/cli 全局安装的 npm 包,提供了终端里的vue命令(如:vue create .vue ...

  8. Codeforces 934C - A Twisty Movement

    934C - A Twisty Movement 思路:dp 很容易想到要预处理出1的前缀和pre[i]和2的后缀和suf[i] 然后枚举区间,对于每个区间如果能求出最长递减序列的长度,那么就能更新答 ...

  9. 第 7 章 多主机管理 - 046 - 创建 Machine

    创建 Machine Machine 就是运行 docker daemon 的主机. “创建 Machine” 指的就是在 host 上安装和部署 docker. 创建第一个 machine: hos ...

  10. 对nginx进行平滑升级

    1.查看服务器当前nginx版本 [root@instance-hwl9ix5l licenses]# nginx -v           #查看版本 nginx: nginx version: n ...