码迷,mamicode.com
首页 > 其他好文 > 详细

Breaking Biscuits(模板题-求凸边形的宽)

时间:2018-08-28 20:16:32      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:this   some   abs   描述   wal   sub   ica   only   err   

 Breaking Biscuits

时间限制: 1 Sec  内存限制: 128 MB  Special Judge
提交: 70  解决: 26
[提交] [状态] [讨论版] [命题人:admin]

题目描述

This year, Walter’s workplace resolved to try something radically different: they’re going to change the weekly order of biscuits for the break room to a whole other brand.
Biscuits come in many shapes and sizes, but the particular brand they settled on has two special qualities:
? It is completely planar (two-dimensional);
? It is perfectly polygon-shaped.
However, disaster struck immediately: the available mugs in the break room are too narrow for Walter to be able to dunk these new biscuits into, no matter what combination of rotations along the three axes he tries.
There is only one thing for it: Walter will need to order another mug.
Before taking this drastic step, it is vital to know how wide the diameter of this mug will need to be in order to succesfully accommodate a (possibly rotated) biscuit of the new brand.
 

 

输入

? One line containing an integer N (3 ≤ N ≤ 100), the number of vertices in the biscuit.
? Each of the following N lines contains two space-separated integers Xi and Yi (?105 ≤Xi, Yi ≤ 105), the coordinates of the i-th vertex.
Vertices are always given in anti-clockwise order. Also, as anyone can tell you, biscuits never self-intersect and always have positive area.

 

输出

Output the minimum possible diameter of the new mug, in order that it can fit the new kind of biscuit fully inside in at least one orientation. The output must be accurate to an absolute or relative error of at most 10?6.
 

 

样例输入

4
0 0
5 0
5 2
0 2

 

样例输出

2.0

 

技术分享图片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=115;
 4 int n;
 5 double ans=1e100;
 6 struct P
 7 {
 8     int x,y;
 9     P() {}
10     P(int _x,int _y)
11     {
12         x=_x,y=_y;
13     }
14     P operator-(P b)
15     {
16         return P(x-b.x,y-b.y);
17     }
18     double len()
19     {
20         return hypot(x,y);
21     }
22 } a[N];
23 double cross(P a,P b)
24 {
25     return a.x*b.y-a.y*b.x;
26 }
27 double dist(P p,P a,P b)
28 {
29     return cross(p-a,b-a)/(b-a).len();
30 }
31 void solve()
32 {
33     for(int i = 1; i <= n; i++)
34     {
35         for(int j = 1; j < i; j++)
36         {
37             double l=1e100,r=-1e100;
38             for(int k = 1; k <= n; k++)
39             {
40                 l=min(l,dist(a[k],a[i],a[j]));
41                 r=max(r,dist(a[k],a[i],a[j]));
42             }
43             r-=l;
44             ans=min(ans,r);
45         }
46     }
47 }
48 int main()
49 {
50     scanf("%d",&n);
51     for(int i=1; i<=n; i++) scanf("%d %d",&a[i].x,&a[i].y);
52     solve();
53     printf("%.10f\n",ans);
54     return 0;
55 }
View Code

 

Breaking Biscuits(模板题-求凸边形的宽)

标签:this   some   abs   描述   wal   sub   ica   only   err   

原文地址:https://www.cnblogs.com/lglh/p/9550162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!