UVa-10652|UVa-10652 包装木板

UVa-10652 包装木板Input: standard input
Output: standard output
Time Limit: 2 seconds


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, j where 0 <= x, y, w, h <=10000 and –90° < j <=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. j is the angle between the height axis of the board to the y-axis in degrees, positive clockwise. That is, if j = 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 (%).

Sample InputOutput for 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
64.3 %

Swedish National Contest

The Sample Input and Sample Output corresponds to the given picture
题解:白书上的原题。
把每个矩形的四个顶点都找出来,做凸包就是最小的多边形,计算面积就从一个点出发向每个点都连一条对角线,将多边形分成若干个三角形再计算。
比较坑的是,数字和“%”之间还有一个空格>_

#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int INF=0x3f3f3f3f; const LL inf=0x3f3f3f3f3f3f3f3fLL; const double eps=1e-10; struct Point{ double x,y; Point(double xx=0,double yy=0) : x(xx),y(yy) {} } p[2010],ch[2010]; typedef Point Vector; //定义向量 Vector operator + (Vector a,Vector b) { return Vector(a.x+b.x,a.y+b.y); } Vector operator - (Vector a,Vector b) { return Vector(a.x-b.x,a.y-b.y); } Vector operator * (Vector a,Vector b) { return Vector(a.x*b.x,a.y*b.y); } Vector operator / (Vector a,Vector b) { return Vector(a.x/b.x,a.y/b.y); } bool operator < (const Point &a,const Point &b) { return a.x==b.x? a.y0) return Length(v3); else return fabs(Cross(v1,v2))/Length(v1); } */ Point GetLineProjection(Point p,Point a,Point b)//点在直线的投影点 { Vector v=b-a; return a+v*(Dot(v,p-a)/Dot(v,v)); }double Polygonarea(Point *p,int n)//多边形面积(凸,凹) { double area=0; for(int i=1; i1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--; ch[m++]=p[i]; } int k=m; for(int i=n-2; i>=0; i--) { while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--; ch[m++]=p[i]; } if(n>1) m--; return m; }int N,n; double x,y,w,h,j; int main() { scanf("%d",&N); while(N--) { int flag=0; double area1=0,area2=0; scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j); Point O{x,y}; double rad=-torad(j); p[flag++]=O + Rotate(Vector(-w/2,-h/2),rad); p[flag++]=O + Rotate(Vector(w/2,-h/2),rad); p[flag++]=O + Rotate(Vector(-w/2,h/2),rad); p[flag++]=O + Rotate(Vector(w/2,h/2),rad); area1+=w*h; } int cnt=Convexhull(p,flag,ch); area2=Polygonarea(ch,cnt); printf("%.1lf %%\n",area1*100/area2); } return 0; }


【UVa-10652|UVa-10652 包装木板】

posted @ 2018-07-29 20:12 SongHL 阅读( ...) 评论( ...) 编辑 收藏

    推荐阅读