zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    2篇msdn上关于语言的文章
    软件测试常用术语表
    Log4net hello world
    自己动手创建 .NET Framework 语言编译器
    ASPNET一个错误记录错误 1 未能找到元数据文件“C:/windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServi
    读书笔记之C#的is和as操作符强制类型转换收藏
    SQL Server不允许进行远程连接的解决办法
    经典回顾Class.forName()
    wince初学记录 (1)
    关于asp.net中dataList控件的使用学习记录
  • 原文地址:https://www.cnblogs.com/lglh/p/9550162.html
Copyright © 2011-2022 走看看