Link: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & amp; Itemid = 8 & page = show_problem & amp; Category = & amp; problem = 1006
Problem
Useless tile Packers
Input:Standard Input
Output:Standard output
Yes, as you have apprehendedUseless tile Packers(UTP) Pack tiles. the tiles are of uniform thickness and have simple polygonal shape. for each tile a container is M m-built. the floor of the container is a convex polygon and under this constraint it has the minimum possible space inside to hold the tile it is built. but this strategy leads to wasted space inside the container.
The UTP authorities are interested to know the percentage of wasted space for a given tile.
Input
The input file consists of several data blocks. Each data block describes one tile.
The first line of a data block contains an integerN(3 <= n <= 100) indicating the number of Corner Points of the tile. Each of the nextNLines contains two integers giving (X,Y) Co-ordinates of a corner point (determined using a suitable origin and orientation of the axes) where 0 <= x ,,Y <= 1000.Starting from the first point given in the input the corner points occur in the same order on the boundary of the tile as they appear in the input. No three consecutive points are co-linear.
The input file terminates with a value of 0N.
Output
For each tile in the input output the percentage of wasted space rounded to two digits after the decimal point. Each output must be on a separate line. Print a blank line after each output block.
Sample Input
5
0 0
2 0
2 2
1 1
0 2
5
0 0
0 2
1 3
2 2
2 0
0
Sample output
Tile #1
Wasted space = 25.00%
Tile #2
Wasted space = 0.00%
________________________________________________________________________________
Rezaul Alam Chowdhury
-= -=
Let us look at the free area and simply convert it to the area before the convex hull is built, and the area after the convex hull is built, subtract, and then divide.
I made a silly mistake. I defined the function of the product of the cross and the function type of the distance as bool. I tried to get the result and debug it twice, khan !!!
1 #include <stdio.h> 2 #include <math.h> 3 #include <string.h> 4 #include <stdlib.h> 5 #include <iostream> 6 #include <algorithm> 7 8 using namespace std; 9 #define MAXX 10510 #define eps 1e-811 12 typedef struct point13 {14 double x;15 double y;16 }point;17 18 bool xy(double x,double y){ return x<y-eps; }19 bool dy(double x,double y){ return x>y+eps; }20 bool xyd(double x,double y){ return x<y+eps; }21 bool dyd(double x,double y){ return x>y-eps; }22 bool dd(double x,double y){ return fabs(x-y)<eps; }23 24 double crossProduct(point a,point b,point c)25 {26 return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);27 }28 double dist(point a,point b)29 {30 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));31 }32 33 point p[MAXX];34 point stk[MAXX];35 int top;36 37 bool cmp(point a,point b)38 {39 double len=crossProduct(p[0],a,b);40 if(dd(len,0.0))41 {42 return xy(dist(p[0],a),dist(p[0],b));43 }44 return xy(len,0.0);45 }46 47 void Graham(int n)48 {49 int tmp=0;50 for(int i=1; i<n; i++)51 {52 if(xy(p[i].x,p[tmp].x) || dd(p[i].x,p[tmp].x) && xy(p[i].y,p[tmp].y))53 {54 tmp=i;55 }56 }57 swap(p[0],p[tmp]);58 sort(p+1,p+n, cmp);59 60 stk[0]=p[0];61 stk[1]=p[1];62 top=1;63 for(int i=2; i<n; i++)64 {65 while(top && xyd(crossProduct(stk[top],stk[top-1],p[i]),0.0))66 top--;67 stk[++top]=p[i];68 }69 }70 71 double Area(int n,point ss[])72 {73 double ans=0.0;74 for(int i=2; i<n; i++)75 {76 ans+=crossProduct(ss[0],ss[i-1],ss[i]);//printf("%lf^^\n",ans);77 }78 return fabs(ans)/2.0;79 }80 81 int main()82 {83 int n,m,i,j;84 int cas=1;85 while(scanf("%d",&n)!=EOF &&n)86 {87 for(i=0; i<n; i++)88 scanf("%lf%lf",&p[i].x,&p[i].y);89 double ans_min=Area(n,p);90 Graham(n);//printf("%d--",top);91 double ans_max=Area(top+1,stk);92 printf("Tile #%d\n",cas++);93 printf("Wasted Space = %.2lf %%\n\n",(ans_max-ans_min)/ans_max*100);94 }95 return 0;96 }
View code
For the first question about the server, make an email to commemorate and send the message to the server.
××××××××××××××××××××××××××××××××××××××××××× ××××××××××××××××××××××××××××××××××××××××××× ××××××××××××××××××××××××××××
Hi,
This is an automatic response from ultraviolet A online judge.
Your submission with number
14050702For the problem
10065-useless tile PackersHas succeeded with verdict
Accepted.
Congratulations! Now it is time to try a new problem.
Best regards,
The ultraviolet A online judge team ×××××××××××××××××××××××××××××××××××××× ××××××××××××××××××××××××××××××××××××××××××× ×××××××××××××××××××××××××××××××××