Kite(几何+镜面对称)

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.
Problem illustration
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

inputoutput
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.
 
 
 

 题意:求四边形,镜面对称的点;

思路:首先镜面对称,那么点的个数就是一定是偶数倍的。然后既然是镜面对称,那么他的投影点和点的镜面的距离一定是相等的;

 

转载请注明出处:寻找&星空の孩子  

 

 

 

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 }
View Code

 

 
 
 
 
 
 
 
 
 
posted @ 2015-04-19 21:32  寻找&星空の孩子  阅读(643)  评论(0编辑  收藏  举报