C. Kite
1000ms 1000ms 65536KB
Vova bought a kite construction kit in a market in Guangzhou. The next day the weather was good and he decided to make the kite and fly it. Manufacturing instructions, of course, were only in Chinese, so Vova decided that he can do without it. After a little tinkering, he constructed a kite in the form of a flat quadrangle and only needed to stick a tail to it.
And then Vova had to think about that: to what point of the quadrangle's border should he stick the kite tail? Intuition told him that in order to make the kite fly steadily, its tail should lie on some axis of symmetry of the quadrangle. On the left you can see two figures of stable kites, and on the right you can see two figures of unstable kites.
How many points on the quadrangle border are there such that if we stick a tail to them, we get a stable kite?
Input
The four lines contain the coordinates of the quadrangle's vertices in a circular order. All coordinates are integers, their absolute values don't exceed 1 000. No three consecutive quadrangle vertices lie on the same line. The opposite sides of the quadrangle do not intersect.
Output
Print the number of points on the quadrangle border where you can attach the kite.
Sample Input
input | output |
---|---|
0 0 1 2 2 2 2 1 |
2 |
0 0 2 1 2 2 0 2 |
0 |
Hint
The axis of symmetry of a flat figure is a straight line lying in the figure plane and dividing the figure to the two halves that are each other's mirror image.
題意:求四邊形,鏡面對稱的點;
思路:首先鏡面對稱,那麼點的個數就是一定是偶數倍的。然後既然是鏡面對稱,那麼他的投影點和點的鏡面的距離一定是相等的;
轉載請註明出處:尋找&星空の孩子
題目連結:Kite:http://www.bnuoj.com/bnuoj/problem_show.php?pid=33563
so......
1 #include<cstdio> 2 #include<cmath> 3 #include<iostream> 4 #define PI acos(-1.0) 5 using namespace std; 6 7 struct Point 8 { 9 double x,y; 10 Point(double x=0,double y=0):x(x),y(y){}//建構函式,方便程式碼編寫 11 }; 12 13 typedef Point Vector;//Vector只是Point的別名 14 15 //向量+向量=向量; 向量+點=點 16 Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);} 17 18 //點-點=向量 19 Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);} 20 21 //向量*數=向量 22 Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);} 23 24 //向量/數=向量 25 Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);} 26 27 // 28 bool operator < (const Point& a,const Point& b){return a.x<b.x||(a.x==b.x && a.y<b.y);} 29 30 // 31 const double eps = 1e-10; 32 //三態函式 33 int dcmp(double x){if(fabs(x)<eps)return 0;else return x < 0 ? -1 : 1;} 34 //相等 35 bool operator == (const Point& a,const Point& b){return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;} 36 37 //點積 x1*x2+y1*y2 38 //向量垂直點積為0; 39 //利用點積,求向量的夾角和長度; 40 double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;} 41 double length(Vector A){return sqrt(Dot(A,A));} 42 double Angle(Vector A,Vector B){return acos(Dot(A,B)/length(A)/length(B));} 43 44 //叉積 x1*y2-x2*y1 45 //向量共線叉積為0; 46 //叉積為三角形有向面積的2倍 47 //已知三點求三角形面積 48 double Cross(Vector A,Vector B){return A.x*B.y-B.x*A.y;} 49 double Area2(Point A,Point B,Point C){return Cross(B-A,C-A);} 50 51 double DistanceToLine(Point P,Point A,Point B) 52 { 53 Vector v1=B-A, v2=P-A; 54 return fabs(Cross(v1,v2))/length(v1);//如果不取絕對值,得到的是有向距離; 55 } 56 57 Point GetLineProjection(Point P,Point A,Point B) 58 { 59 Vector v=B-A; 60 return A+v*(Dot(v,P-A)/Dot(v,v)); 61 } 62 63 64 Point div(Point &A,Point &B) 65 { 66 Point E; 67 E.x=(A.x+B.x)/2; 68 E.y=(A.y+B.y)/2; 69 return E; 70 } 71 int main() 72 { 73 Point A,B,C,D; 74 Point AB,BC,CD,DA; 75 while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y)!=EOF) 76 { 77 AB=div(A,B); 78 BC=div(B,C); 79 CD=div(C,D); 80 DA=div(D,A); 81 82 // printf("%lf%lf\n%lf%lf\n%lf%lf\n%lf%lf\n",A.x,A.y,B.x,B.y,C.x,C.y,D.x,D.y); 83 int cnt=0; 84 Point P1,P2,P3,P4; 85 double x1,x2,x3,x4; 86 //A--C 87 P1=GetLineProjection(B,A,C); 88 P2=GetLineProjection(D,A,C); 89 x1=DistanceToLine(B,A,C); 90 x2=DistanceToLine(D,A,C); 91 if(P1==P2&&x1==x2) cnt+=2; 92 // if(Area2(A,B,C)==Area2(A,D,C)) cnt+=2; 93 94 //B--D 95 P1=GetLineProjection(A,B,D); 96 P2=GetLineProjection(C,B,D); 97 x1=DistanceToLine(A,B,D); 98 x2=DistanceToLine(C,B,D); 99 if(P1==P2&&x1==x2) cnt+=2; 100 // if(Area2(B,A,D)==Area2(B,C,D)) cnt+=2; 101 102 //BC--DA 103 P1=GetLineProjection(A,BC,DA); 104 P2=GetLineProjection(D,BC,DA); 105 P3=GetLineProjection(B,BC,DA); 106 P4=GetLineProjection(C,BC,DA); 107 x1=DistanceToLine(A,BC,DA); 108 x2=DistanceToLine(D,BC,DA); 109 x3=DistanceToLine(B,BC,DA); 110 x4=DistanceToLine(C,BC,DA); 111 if(P1==P2&&P3==P4&&x1==x2&&x3==x4) cnt+=2; 112 // if(Area2(D,DA,BC)+Area2(D,BC,C)==Area2(A,DA,BC)+Area2(A,BC,B)) cnt+=2; 113 114 //AB--CD 115 P1=GetLineProjection(A,AB,CD); 116 P2=GetLineProjection(B,AB,CD); 117 P3=GetLineProjection(C,AB,CD); 118 P4=GetLineProjection(D,AB,CD); 119 x1=DistanceToLine(A,AB,CD); 120 x2=DistanceToLine(B,AB,CD); 121 x3=DistanceToLine(C,AB,CD); 122 x4=DistanceToLine(D,AB,CD); 123 if(P1==P2&&P3==P4&&x1==x2&&x3==x4) cnt+=2; 124 // if(Area2(A,AB,CD)+Area2(A,CD,D)==Area2(B,AB,CD)+Area2(B,CD,C)) cnt+=2; 125 126 printf("%d\n",cnt); 127 } 128 return 0; 129 }