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/ ...
随机推荐
- windows 上让文件类型和程序关联的批处理程序。
文件关联工具 地址: https://github.com/wll8/assoc-tool 本工具可以用来为你的便携程序添加文件关联,比如 nodepad2.exe . vscode 或其他图片处理程 ...
- 原生js仿jquery一些常用方法
原生js仿jquery一些常用方法 下面小编就为大家带来一篇原生js仿jquery一些常用方法(必看篇).小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 最近迷上了原 ...
- Python数据类型补充2
四.列表 常用操作+内置的方法: 1.按索引存取值(正向存取+反向存取):即可存也可以取 # li=['a','b','c','d'] # print(li[-1]) # li[-1]='D' # p ...
- SAP固定资产业务场景及方案
SAP固定资产业务场景及方案 http://mp.weixin.qq.com/s/hYlaNHJMQBTZpyFAmP2h3A 对于FICO应用资深专家或顾问,须业务场景及需求成竹在胸:对于非财务顾问 ...
- MySQL中查询时间最大的一条记录
在项目中要查询用户最近登录的一条记录的 ip 直接写如下 SQL: SELECT ip,MAX(act_time) FROM users_login GROUP BY login_id; 但是这样是取 ...
- _killerstreak
`count`连杀或终结连杀的数量(最大支持10个) `announceFlag` 0-不广播1-只广播连杀消息2-只广播终结连杀消息3-广播连杀与终结连杀消息 `rewId` 连杀奖励模板Id,对应 ...
- VirtualBox安装Centos6.8出现——E_INVALIDARG (0x80070057)
VirtualBox使用已有的虚拟硬盘出错: 问题描述:UUID已经存在 Cannot register the hard disk 'E:\system_iso\centos6.8.vdi' {05 ...
- [Python]IO密集型任务 VS 计算密集型任务
所谓IO密集型任务,是指磁盘IO.网络IO占主要的任务,计算量很小.比如请求网页.读写文件等.当然我们在Python中可以利用sleep达到IO密集型任务的目的. 所谓计算密集型任务,是指CPU计算占 ...
- 关于JAVA中包装类的是什么类型传递这个问题的笔记
背景知识: 如果参数类型是原始类型,那么传过来的就是这个参数的一个副本,也就是这个原始参数的值.如果在函数中改变了副本的值不会改变原始的值. 如果参数类型是引用类型,那么传过来的就是这个参数的引用,这 ...
- 获取指定tag的代码
git checkout v1.0.3 再使用ls查看就可以了