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

Posted lglh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Breaking Biscuits(模板题-求凸边形的宽)相关的知识,希望对你有一定的参考价值。

 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
",ans);
54     return 0;
55 }
View Code

 















以上是关于Breaking Biscuits(模板题-求凸边形的宽)的主要内容,如果未能解决你的问题,请参考以下文章

模板三分——cf1355E

旋转卡壳模板

A Round Peg in a Ground Hole POJ - 1584(凸边形与圆相交)

Breaking Good

Doors Breaking and Repairing CodeForces - 1102C (思维)

[Codeforces 507E] Breaking Good