UVA10652木板包装

Posted mediocrekonjac

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10652木板包装相关的知识,希望对你有一定的参考价值。

凸包

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define N 610
 4 #define rep(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
 5 #define dep(a,b,c) for(register int (a)=(b);a>=(c);--(a))
 6 #define RG register
 7 #define IL inline 
 8 #define PN printf("
")
 9 #define PF(a) printf("%.1lf%%",(a))
10 #define mst(a,b) memset((a),(b),sizeof((a)))
11 #define torad(a) ((a)*3.1415926535/180)
12 #define eps 1e-6
13 IL int isitdigit(char c){    return c<=9&&c>=0;    }
14 IL int read()
15 {
16     RG int s;RG char c;
17     while(!isitdigit(c=getchar()));
18     for(s=c-0;isitdigit(c=getchar());s=(s<<1)+(s<<3)+c-0);
19     return s;
20 }
21 IL bool cmp(double a,double b)
22 {    return ((a<=b)&&(b-a>=eps));    }
23 struct point
24 {
25     double x,y;
26     point(double a=0,double b=0):x(a),y(b){}
27     IL const point operator * (double another)
28     const{    return (point){ x*another,y*another};    }
29     IL const point operator - (const point another)
30     const{    return (point){ x-another.x,y-another.y};    }
31     IL const point operator +(const point another)
32     const{    return (point){ x+another.x,y+another.y};    }
33     IL const bool operator <(const point another)
34     const{    return cmp(x,another.x)||(!cmp(another.x,x)&&cmp(y,another.y));    }
35 }p[N*4];
36 IL const double dot(const point a,const point b)
37 {    return a.x*b.x+a.y*b.y;    }
38 IL const double det(const point a,const point b)
39 {    return a.x*b.y-a.y*b.x;    }
40 IL const double mod(const point a)
41 {    return sqrt(dot(a,a));    }
42 int n,tot;
43 double s;
44 int st[N*4],top;
45 int main()
46 {
47     freopen("newfile.in","r",stdin);
48     int T=read();
49     while(T--)
50     {
51         s=tot=0,n=read();
52         rep(i,1,n)
53         {
54             RG double x,y,w,h,j;
55             scanf("%lf %lf %lf %lf %lf",&x,&y,&w,&h,&j);
56             j=-torad(j);
57             RG point c(x,y),bh(-h*sin(j)/2,h*cos(j)/2),bw(w*cos(j)/2,w*sin(j)/2);
58             s+=w*h;
59             p[++tot]=c+bh+bw;
60             p[++tot]=c-bh+bw;
61             p[++tot]=c-bh-bw;
62             p[++tot]=c+bh-bw;
63         }
64         sort(p+1,p+1+tot);
65         mst(st,0);top=0;
66         rep(i,1,tot)
67         {
68             if(top<=1) st[++top]=i;
69             else
70             {
71                 RG point & last=p[st[top-1]];
72                 RG point & now=p[st[top]];
73                 RG point & pre=p[i];
74                 if(!cmp(det(now-last,pre-now),0)) st[++top]=i;
75                 else --top,--i;
76             }
77         }
78         RG int size=--top;
79         dep(i,tot,1)
80         {
81             if(top<=size+1) st[++top]=i;
82             else
83             {
84                 RG point & last=p[st[top-1]];
85                 RG point & now=p[st[top]];
86                 RG point & pre=p[i];
87                 if(!cmp(det(now-last,pre-now),0)) st[++top]=i;
88                 else --top,++i;
89             }
90         }
91         RG double ans=0;
92         rep(i,2,top)    ans+=det(p[st[i-1]],p[st[i]])/2;    
93         PF(100*s/ans),PN;
94     }
95     return 0;
96 }

 

以上是关于UVA10652木板包装的主要内容,如果未能解决你的问题,请参考以下文章

计算几何-UVa10652

●UVA 10652 Board Wrapping

Uva 10652 Board Wrapping

UVA 10652 Board Wrapping(凸包)

UVA–10652 Board Wrapping[凸包]

几何算法专题