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. WebGIS前端地图显示之根据地理范围换算出瓦片行列号的原理(核心)

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.前言 在上一节中我们知道了屏幕上一像素等于实际中多少单位长度(米或 ...

  3. http协议的状态码解释

    一些常见的状态码为: 200 – 服务器成功返回网页 404 – 请求的网页不存在 503 – 服务器超时 下面提供 HTTP 状态码的完整列表.点击链接可了解详情.您也可以访问 HTTP 状态码上的 ...

  4. 【抓包】【Charles】

    Mac抓包神器-----Charles Charles 是一款Mac上的HTTP代理服务器.HTTP监视器.反向代理服务器,可以让开发者监视查看所有连接互联网的HTTP通信,包括请求,响应和HTTP头 ...

  5. XMind 8 Update 7 Pro 激活码

    XMind Update Pro 邮箱:x@iroader 序列号: XAka34A2rVRYJ4XBIU35UZMUEEF64CMMIYZCK2FZZUQNODEKUHGJLFMSLIQMQUCUB ...

  6. Java+selenium 爬Boss直聘中职位信息,薪资水平和职位描述

      需要下载合适的selenium webdirver jar包和对应浏览器的驱动jar包 import org.openqa.selenium.By; import org.openqa.selen ...

  7. python web.py操作mysql数据库,实现对数据库的增删改查操作

    使用web.py框架,实现对mysql数据库的增删改查操作: 该示例代码中连接的是本地数据库testdb,user表,表结构比较简单,只有两个字段:mobile和passwd,类型均为字符型 实际应用 ...

  8. bufferedReader中的数据, 只是读过一次, 就没有了(拿走,自然就没了),只能读一次( load, readLine 等只要是读操作)

  9. Eclipse搭建maven项目的流程,聚合所有的子模块项目

    Eclipse搭建maven项目的流程 2018年03月01日 15:47:03 阅读数:22 1:搭建parent工程,用来聚合所有的子模块项目 2:搭建公共使用的模块common 这里你要点击空白 ...

  10. 力扣(LeetCode) 104. 二叉树的最大深度

    给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定二叉树 [3,9,20,null,null,15,7], ...