zoukankan      html  css  js  c++  java
  • UVA 10652 Board Wrapping(凸包)

    The small sawmill in Mission, British Columbia, has
    developed a brand new way of packaging boards for
    drying. By fixating the boards in special moulds, the
    board can dry efficiently in a drying room.
    Space is an issue though. The boards cannot be
    too close, because then the drying will be too slow.
    On the other hand, one wants to use the drying room
    efficiently.
    Looking at it from a 2-D perspective, your task is
    to calculate the fraction between the space occupied by
    the boards to the total space occupied by the mould.
    Now, the mould is surrounded by an aluminium frame
    of negligible thickness, following the hull of the boards’
    corners tightly. The space occupied by the mould
    would thus be the interior of the frame.
    Input
    On the first line of input there is one integer, N ≤ 50,
    giving the number of test cases (moulds) in the input. After this line, N test cases follow. Each test case
    starts with a line containing one integer n, 1 < n ≤ 600, which is the number of boards in the mould.
    Then n lines follow, each with five floating point numbers x, y, w, h, ϕ where 0 ≤ x, y, w, h ≤ 10000
    and −90◦ < ϕ ≤ 90◦
    . The x and y are the coordinates of the center of the board and w and h are the
    width and height of the board, respectively. ϕ is the angle between the height axis of the board to the
    y-axis in degrees, positive clockwise. That is, if ϕ = 0, the projection of the board on the x-axis would
    be w. Of course, the boards cannot intersect.
    Output
    For every test case, output one line containing the fraction of the space occupied by the boards to the
    total space in percent. Your output should have one decimal digit and be followed by a space and a
    percent sign (‘%’).
    Note: The Sample Input and Sample Output corresponds to the given picture
    Sample Input
    1
    4
    4 7.5 6 3 0
    8 11.5 6 3 0
    9.5 6 6 3 90
    4.5 3 4.4721 2.2361 26.565
    Sample Output
    64.3 %

    题解:求矩形面积与凸包面积的比例,顺时针一定要是负....错了半天。。。还有给的ang要转化为rad

    代码:

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 const double Pi=acos(-1.0);
     8 struct Point{
     9     double x,y;
    10     Point(double x=0,double y=0):x(x),y(y){}
    11 };
    12 typedef Point Vector;
    13 bool operator < (Point a,Point b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
    14 Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
    15 double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
    16 double Length(Vector a){return sqrt(Dot(a,a));}
    17 double Angle(Vector a,Vector b){return acos(Dot(a,b)/Length(a)/Length(b));}
    18 Vector Rotate(Vector a,double rad){return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));}
    19 double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
    20 Point operator + (Point a,Vector b){return Point(a.x+b.x,a.y+b.y);}
    21 Point getdot(Point a,Vector b,double ang){return a+Rotate(b,ang);}
    22 double getrad(double ang){return Pi*(ang/180);}
    23 Point ans[2500],at[2500];
    24 int nu;
    25 double polygonArea(){
    26     int k=0;
    27     for(int i=0;i<nu;i++){
    28         while(k>1&&Cross(ans[k-1]-ans[k-2],at[i]-ans[k-2])<=0)k--;
    29         ans[k++]=at[i];
    30     }
    31     int p=k;
    32     for(int i=nu-1;i>=0;i--){
    33         while(k>p&&Cross(ans[k-1]-ans[k-2],at[i]-ans[k-2])<=0)k--;
    34         ans[k++]=at[i];
    35     }
    36     double x=0;
    37     k--;
    38     if(k<2)return 0;
    39     for(int i=1;i<k-1;i++)x+=Cross(ans[i]-ans[0],ans[i+1]-ans[0]);
    40     return x/2;
    41 }
    42 int main(){
    43     int T,n;
    44     double x,y,w,h,ang;
    45     scanf("%d",&T);
    46     while(T--){
    47         double area1=0,area2=0;
    48         nu=0;
    49         scanf("%d",&n);
    50         while(n--){
    51             scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&ang);
    52             area2+=w*h;
    53             Point a;
    54             ang=-getrad(ang);//因为是顺时针旋转的,所以要是负的。。。。。 
    55             at[nu++]=getdot(Point(x,y),Vector(w/2,h/2),ang);
    56             at[nu++]=getdot(Point(x,y),Vector(-w/2,h/2),ang);
    57             at[nu++]=getdot(Point(x,y),Vector(w/2,-h/2),ang);
    58             at[nu++]=getdot(Point(x,y),Vector(-w/2,-h/2),ang);
    59         }
    60         sort(at,at+nu);
    61         area1=polygonArea();
    62     //    printf("%lf %lf
    ",area1,area2);
    63         printf("%.1lf %%
    ",100*area2/area1);
    64     }
    65     return 0;
    66 }
  • 相关阅读:
    shell 1>&2 2>&1 &>filename重定向的含义和区别
    Nginx日志切割
    mycli工具mysql命令自动补全
    2019-2020-2 20175317钟睿文《网络对抗技术》Exp9 Web安全基础
    2019-2020-2 20175317钟睿文《网络对抗技术》Exp8 Web基础
    2019-2020-2 20175317钟睿文《网络对抗技术》Exp7 网络欺诈防范
    2019-2020-2 20175317钟睿文《网络对抗技术》Exp6 MSF基础应用
    2019-2020-2 20175317钟睿文《网络对抗技术》Exp5 信息搜集与漏洞扫描
    2019-2020-2 20175317钟睿文《网络对抗技术》Exp4 恶意代码分析
    2019-2020-2 20175317钟睿文《网络对抗技术》Exp3 免杀原理与实践
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4942424.html
Copyright © 2011-2022 走看看