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. SAP本地化-银企直连

    SAP本地化-银企直连 http://blog.sina.com.cn/s/blog_a0de8cc80101dee1.html 一.发展历史 2011年,在SAP ECC6 Ehp5中,通过功能增强 ...

  2. java中垃圾回收算法讲解

      判断对象是否存活的方法: 一.引用计数算法(Reference Counting) 介绍:给对象添加一个引用计数器,每当一个地方引用它时,数据器加1:当引用失效时,计数器减1:计数器为0的即可被回 ...

  3. Python 爬虫入门3种方法

    Python 2.0 url = "http://www.baidu.com" print '第一种方法' response1 = urllib2.urlopen(url) pri ...

  4. ashx图片上传接收

    发送数据流方法 /// <summary> /// PostBinaryData /// </summary> /// <param name="url&quo ...

  5. _instance_reset

    制作多功能Item.creature及gameobject 中第19个功能 重置副本,关联到该表. 当该表中配置,且玩家有这个副本这个难度的进度时,功能宝石中会出现该副本的名字,点击可以重置副本 ma ...

  6. RedHat(Linux)下安装Python3步骤

    1. 下载解压.$ wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz$ tar zxvf Python-3.4.1.tgz 2 ...

  7. git difftool和mergetool图形化

    1.当然是先安装Beyond Compare3 (此处省略安装步骤,自行百度) 2.设置difftool git config --global diff.tool bc3 git config -- ...

  8. 浅谈Java简单实现的生产者与消费者问题

    一.面对生产者和消费者的问题,首先我们得明白几点: 生产者:生产数据:消费者:消费数据.消费者在没有数据可供消费的情况下,不能消费:生产者在原数据没有被消费掉的情况下,不能生产新数据.假设,数据空间只 ...

  9. Python全栈开发-Day2-Python基础2

    本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 定义列表 ...

  10. python中装饰器

    在介绍装饰器之前,要先了解装饰器的相关基础知识. 嵌套函数: 最后引入一个基本的装饰器的例子: __author__ = "YanFeixu" import time def ti ...