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/ ...
随机推荐
- js捕获错误
文: http://www.jb51.net/article/78764.htm 用window.onerror捕获并上报Js错误的方法 前两天有个2048游戏的用户反馈说,打开游戏后不能玩儿,只有一 ...
- Redux基础使用
Redux基础使用: 简介:这里是从需求来响应的执行操作redux,所以理解起来更加的容易铭记在心的三点:action/reducer/store 除此之外就是react/react native的基 ...
- hdu 3829 Cat VS Dog 二分图匹配 最大点独立集
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Prob ...
- Python.错误解决:scrapy 没有crawl 命令
确保2点: 1.把爬虫.py复制到spiders文件夹里 如执行scrapy crawl demo ,spiders里面就要有demo.py文件 2.在项目文件夹内执行命令 在scrapy.cfg所在 ...
- Java中的long与double的区别
1.long与double在java中本身都是用64位存储的,但是他们的存储方式不同,导致double可储存的范围比long大很多 2.long可以准确存储19位数字,而double只能准备存储16位 ...
- Panda3D
Panda3D 是个开源的游戏及物理引擎(也支持ODE及Bullet). 相关链接:网站: https://www.panda3d.org/下载: https://www.panda3d.org/do ...
- tomcat热部署.class
本人是在维护公司系统时遇到的问题,由于公司的系统是部署到客户服务器上,而系统中存在的问题又比较多,需要经常维护.如果每次修改完class文件后都需要去重启服务器, 那会给用户的使用造成不便,所以需要使 ...
- java环境变量怎么配置
我们在学习java的时候,必须先来配置一下java的环境变量,也许你不懂什么是java环境变量,我们也不需要懂,你只要知道,java环境变量配置好了,你的电脑就能编译和运行java程序了,这显然是你想 ...
- 一篇很好的java异常框架讲解
https://www.cnblogs.com/itcui/p/6400499.html 其实原作者是csdn的一名博主,实在受不了csdn的广告,所以就摘录这篇
- 基于QT的中国象棋
基于QT的中国象棋,可实现人人对战,人机对战,联网对战,可显示棋谱,可悔棋. 还有一些小毛病,我之后会找空把这个DEMO重新修改一下上传 链接:https://pan.baidu.com/s/1-eM ...