博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1113 Wall (凸包模板题)
阅读量:5021 次
发布时间:2019-06-12

本文共 5490 字,大约阅读时间需要 18 分钟。

Wall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 32808   Accepted: 11137

Description

Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall. 
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements. 
The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.

Input

The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle. 
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.

Output

Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.

Sample Input

9 100200 400300 400300 300400 300400 400500 400500 200350 200200 200

Sample Output

1628

Hint

结果四舍五入就可以了

Source

 
 
给定n个点,求围一圈围墙使得围墙到每个点的距离大于等于l,求围墙的最小周长。
这道题的关键点是,由于最后是绕着中间的n个点转了一周(2×pi)
每个点对应一定弧度,合起来正好是一个圆的周长。
也就是,最后的答案为凸包的周长加上半径为L的圆的周长。
 
第一次写凸包,感谢适牛的板子,真是炒鸡好用呀喵喵喵。
 
不过引用那里没搞明白QAQ,稍微改了下写法。。
1 /*************************************************************************  2     > File Name: code/poj/1113.cpp  3     > Author: 111qqz  4     > Email: rkz2013@126.com   5     > Created Time: 2015年11月09日 星期一 16时33分28秒  6  ************************************************************************/  7   8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 #include
21 #define fst first 22 #define sec second 23 #define lson l,m,rt<<1 24 #define rson m+1,r,rt<<1|1 25 #define ms(a,x) memset(a,x,sizeof(a)) 26 using namespace std; 27 const double eps = 1E-8; 28 const int dx4[4]={ 1,0,0,-1}; 29 const int dy4[4]={ 0,-1,1,0}; 30 typedef long long LL; 31 const int inf = 0x3f3f3f3f; 32 const double pi = acos(-1.0); 33 const int N=1E3+7; 34 int n,l; 35 int top; 36 int dblcmp(int d) 37 { 38 return d<-eps?-1:d>eps; 39 } 40 struct point 41 { 42 double x,y; 43 point (){} 44 point (double _x,double _y): 45 x(_x),y(_y){}; 46 47 void input() 48 { 49 scanf("%lf %lf",&x,&y); 50 } 51 point operator - (const point &p) const{ 52 return point (x-p.x,y-p.y); 53 } 54 double operator ^ (const point &p) const{ 55 return x*p.y-y*p.x; 56 } 57 bool operator < (const point a)const{ 58 return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:x
p[0].y||(p[i].y==p[0].y&&p[i].x>p[0].x)) 90 swap(p[0],p[i]); 91 } 92 } 93 94 struct cmp 95 { 96 point p; 97 cmp(const point &p0){p=p0;} 98 bool operator()(const point &aa,point &bb) 99 {100 point a=aa,b=bb;101 int d = dblcmp((a-p)^(b-p));102 if (d==0)103 {104 return dblcmp(a.distance(p)-b.distance(p))<0;105 }106 else 107 return d>0;108 }109 110 };111 112 void getconvex(polygon &convex,int &top)113 {114 int i,j,k;115 sort(p,p+n); //极角排序116 convex.n=n;117 118 for ( int i = 0 ; i < min (n,2);i++)119 {120 convex.p[i] = p[i];121 }122 if (n<=2) return ;123 top = convex.n;124 top = 1;125 for ( int i = 2 ; i < n ; i++)126 {127 while (top&&convex.p[top].sub(p[i]).det(convex.p[top-1].sub(p[i]))<=0) top--;128 129 convex.p[++top]=p[i];130 }131 132 int tmp = top;133 convex.p[++top] = p[n-2];134 for (int i = n-3 ; i >= 0 ; i--)135 {136 while (top!=tmp&&convex.p[top].sub(p[i]).det(convex.p[top-1].sub(p[i]))<=0)137 top--;138 convex.p[++top]=p[i];139 }140 // ztop = top;141 142 };143 144 }pol;145 146 int main()147 {148 #ifndef ONLINE_JUDGE 149 freopen("in.txt","r",stdin);150 #endif151 152 while (scanf("%d %d",&n,&l)!=EOF)153 {154 pol.n=n;155 pol.input();156 polygon conv;157 pol.getconvex(conv,top);158 159 double res=0;160 // cout<<"top:"<
<
View Code

 

转载于:https://www.cnblogs.com/111qqz/p/4952325.html

你可能感兴趣的文章
Sam做题记录
查看>>
[bzoj] 2453 维护数列 || 单点修改分块
查看>>
IIS版本变迁
查看>>
BZOJ3884: 上帝与集合的正确用法 拓展欧拉定理
查看>>
mybatis09--自连接一对多查询
查看>>
myeclipse10添加jQuery自动提示的方法
查看>>
【eclipse jar包】在编写java代码时,为方便编程,常常会引用别人已经实现的方法,通常会封装成jar包,我们在编写时,只需引入到Eclipse中即可。...
查看>>
视频监控 封装[PlayCtrl.dll]的API
查看>>
软件工程APP进度更新
查看>>
Python 使用正则替换 re.sub
查看>>
CTF中那些脑洞大开的编码和加密
查看>>
简化工作流程 10款必备的HTML5开发工具
查看>>
c++ 调用外部程序exe-ShellExecuteEx
查看>>
Java进击C#——语法之知识点的改进
查看>>
IdentityServer流程图与相关术语
查看>>
BirdNet: a 3D Object Detection Framework from LiDAR information
查看>>
icon fonts入门
查看>>
【Django】如何按天 小时等查询统计?
查看>>
HDU2191(多重背包)
查看>>
测试用例(一)
查看>>