UVA 10652 Board Wrapping (convex bag)

Source: Internet
Author: User
Tags cos

Title Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286

Ideas

Convex bag

According to the angle and the center point to find the rectangle all points, and then you can apply the convex hull algorithm.

Code

#include <cmath>#include<cstdio>#include<algorithm>using namespacestd;Const DoublePI = ACOs (-1.0);DoubleTorad (DoubleDEG) {returndeg/ the* PI; }//Angled radiansstructPt {Doublex, y; Pt (Doublex=0,Doubley=0): X (x), Y (y) {};}; typedef Pt VEC;VECoperator-(Pt a,pt B) {returnVEC (a.x-b.x,a.y-b.y); }vecoperator+ (VEC A,vec B) {returnVEC (a.x+b.x,a.y+b.y); }BOOL operator< (Constpt& A,Constpt&b) {returna.x<b.x | | (a.x==b.x && a.y<b.y);}DoubleCross (Pt a,pt B) {returna.x*b.y-a.y*b.x;} Vec rotate (Vec A,Doublerad) {    returnVEC (A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD));}intConvexhull (pt* p,intn,pt*ch) {Sort (p,p+N); intm=0;  for(intI=0; i<n;i++) {         while(m>1&& Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--;//Maintenance Convex bagch[m++]=P[i]; }    intk=m;  for(inti=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--; returnm;}DoublePolygonarea (pt* p,intN) {//Polygon Area    Doubles=0;  for(intI=1; i<n-1; i++) S+ = Cross (p[i]-p[0],p[i+1]-p[0]); returns/2;}Const intN =2500+Ten; Pt P[n],ch[n];intN;intMain () {intT; scanf ("%d",&T);  while(t--) {scanf ("%d",&N); intPc=0;Doubles1=0; Doublex,y,w,h,j;  for(intI=0; i<n;i++) {scanf ("%LF%LF%LF%LF%LF",&x,&y,&w,&h,&K); Doubleang=-Torad (j);            Pt o (x, y); P[PC++]= o + rotate (VEC (-w/2,-h/2), ANG); P[PC++]= o + rotate (VEC (w/2,-h/2), ANG); P[PC++]= o + rotate (VEC (-w/2, h/2), ANG); P[PC++]= o + rotate (VEC (w/2, h/2), ANG); S1+ = w*h; }        intm=Convexhull (P,PC,CH); DoubleS2=Polygonarea (ch,m); printf ("%.1LF%%\n", s1* -/S2); }    return 0;}

UVA 10652 Board Wrapping (convex bag)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.