Description
The DIY Furniture company specializes in assemble-it-yourself furniture kits. Typically, the pieces of wood are attached to one another using a wooden peg that fits into pre-cut holes in each piece to be attached. The pegs have a circular cross-section and so are intended to fit inside a round hole.Input
Input consists of a series of piece descriptions. Each piece description consists of the following data:Output
For each piece description, print a single line containing the string:Sample Input
5 1.5 1.5 2.0 1.0 1.0 2.0 2.0 1.75 2.0 1.0 3.0 0.0 2.0 5 1.5 1.5 2.0 1.0 1.0 2.0 2.0 1.75 2.5 1.0 3.0 0.0 2.0 1
Sample Output
HOLE IS ILL-FORMED PEG WILL NOT FIT
Source
Mid-Atlantic 2003
題意:給出n個點,按順時針或逆時針給出,問是不是凸包,和判斷圓在不在凸包內。
如果圖形是凸包,對任意連續三個點a,b,c的叉乘(b-a,c-b)的正負相同,也就是說在同一邊,這樣就可以判斷凸包。
判斷圓在不在凸包內,首先判斷圓心,在不在凸包內,如果在凸包內的話叉乘(b-a,r-a)得到的正負應該與判斷凸包時相同。
然後判斷每條邊到圓心的距離是否大於半徑,由叉乘(b-a,r-a)得到以 為邊的平行四邊形面積,再除以的距離就可以了。
#include#include #include #include #include using namespace std ; #define eps 1e-8 struct node{ double x , y ; }p[10005] , q ; double r , r_x , r_y ; node sub(node a,node b) { a.x -= b.x ; a.y -= b.y ; return a ; } int mul(node a,node b) { if( a.x*b.y - a.y*b.x >= 0 ) return 1 ; else return -1 ; } double dis(node a,node b) { if( fabs(a.x-b.x) < eps ) return fabs(q.x-a.x) ; else if( fabs(a.y-b.y) < eps ) return fabs(q.y-a.y) ; else { node s , e ; s = sub(a,b) ; e = sub(q,b) ; return fabs(s.x*e.y-s.y*e.x)/( sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ) ); } } int main() { int n , i , j , flag ; while( scanf("%d", &n) && n >= 3 ) { scanf("%lf %lf %lf", &r, &q.x, &q.y) ; for(i = 0 ; i < n ; i++) scanf("%lf %lf", &p[i].x, &p[i].y) ; p[n] = p[0] ; flag = mul(sub(p[1],p[0]),sub(p[2],p[1])) ; for(i = 1 ; i < n ; i++) { if( flag != mul(sub(p[i],p[i-1]),sub(p[i+1],p[i]) ) ) break ; } if( i < n ) { printf("HOLE IS ILL-FORMED\n") ; continue ; } for(i = 0 ; i < n ; i++) { if( flag != mul( sub(p[i+1],p[i]),sub(q,p[i]) ) ) break ; //printf("%d %lf\n", i, dis(p[i],p[i+1]) ) ; if( dis(p[i],p[i+1]) - r < 0 ) break ; } if( i < n ) printf("PEG WILL NOT FIT\n") ; else printf("PEG WILL FIT\n") ; } return 0; }