Convex Fence
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 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的更多相关文章
- LightOJ 1239 - Convex Fence 凸包周长
LINK 题意:类似POJ的宫殿围墙那道,只不过这道题数据稍微强了一点,有共线的情况 思路:求凸包周长加一个圆周长 /** @Date : 2017-07-20 15:46:44 * @FileNam ...
- [LeetCode] Erect the Fence 竖立栅栏
There are some trees, where each tree is represented by (x,y) coordinate in a two-dimensional garden ...
- [LeetCode] Convex Polygon 凸多边形
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- [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 ...
- poj 3253 Fence Repair
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42979 Accepted: 13999 De ...
- Leetcode: Convex Polygon
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- CF 484E - Sign on Fence
E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...
- poj3253 Fence Repair
http://poj.org/problem?id=3253 Farmer John wants to repair a small length of the fence around the pa ...
- 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/ ...
随机推荐
- 【搬运工】——Java中的static关键字解析(转)
原文链接:http://www.cnblogs.com/dolphin0520/p/3799052.html static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大 ...
- openlayers空间点查询之GetFeatureInfo
在map对象上注册点击方法监听, 这里我用的是wms,当然你也可以查询wfs map.events.register('click', map, function (e) { ...
- JAVA怎样理解面向对象
一.对象 现实世界中,随处可见的一种事物就是对象,对象是事物存在的实体,如人类.书桌.计算机.高楼大厦等.人类解决问题的方式总是将复杂的事物简单化,于是就会思考这些对象都是由哪些部分组成的.通常都 ...
- 【Selenium2】【selenium之 定位以及切换frame(iframe)】
参考:http://blog.csdn.net/huilan_same/article/details/52200586 总有人看不明白,以防万一,先在开头大写加粗说明一下: frameset不用切, ...
- vue运行报错--preventDefault
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as ...
- servlet中为什么doGet方法没有被调用的一种可能(笔记)
创建了一个servlet,然后在doGet()方法内写一些简单的测试语句,但是在实际运行中发现并没有调用到doGet()方法,后来发现自己在创建servlet是将service()方法也勾选上去了,而 ...
- HTML5语义化
转载自:https://www.cnblogs.com/fliu/articles/5244866.html 1.什么是HTML语义化? 用合理.正确的标签来展示内容,比如h1~h6定义标题,便于开发 ...
- Fat jar用途
1.Fat jar用途 我们都知道默认的eclipse下打包jar时,是无法连同外部引用包一起打包的.所以一般我们可以自己编写MINIFEST.MF文件来手动将需要的jar包加入进来,但是这样对于引用 ...
- Windows Phone 8 开发必备资源
一.MVVM框架推荐 1. MVVM-Light 这个框架是我最常用的MVVM框架之一,它比Prism更轻量级,但对于一般的小应用,功能足够. 官方网站:http://mvvmlight.codepl ...
- sgu 139 Help Needed!
题意:16数码是否有解? 先计算展开成一维后逆序对.如果0在最后一行,那么逆序偶时有解.4*4时(n为偶)0的位置上升一行,逆序对+3或-1(奇偶性变化).(n为奇时+2或+0,不变) #includ ...