uva 11437 - Triangle Fun
计算几何;
直线交点;
1 #include<cstdio> 2 using namespace std; 3 4 struct node 5 { 6 double x,y; 7 node(double x=0,double y=0):x(x),y(y){ } 8 }a,b,c,d,e,f,p,q,r; 9 node operator-(node u,node v){return node(u.x-v.x,u.y-v.y);} 10 node operator+(node u,node v){return node(u.x+v.x,u.y+v.y);} 11 node operator*(node u,double v){return node(u.x*v,u.y*v);} 12 node operator/(node u,double v){return node(u.x/v,u.y/v);} 13 14 double cross(node u,node v) 15 { 16 return u.x*v.y-u.y*v.x; 17 } 18 19 node get(node p,node v,node q,node w) 20 { 21 node u=p-q; 22 double t=cross(w,u)/cross(v,w); 23 return p+v*t; 24 } 25 26 int main() 27 { 28 int n; 29 scanf("%d",&n); 30 while(n--) 31 { 32 scanf("%lf%lf",&a.x,&a.y); 33 scanf("%lf%lf",&b.x,&b.y); 34 scanf("%lf%lf",&c.x,&c.y); 35 d=b+(c-b)/3; 36 e=c+(a-c)/3; 37 f=a+(b-a)/3; 38 p=get(b,e-b,a,d-a); 39 q=get(c,f-c,b,e-b); 40 r=get(c,f-c,d,a-d); 41 printf("%.0lf\n",cross(q-p,r-p)/2); 42 } 43 return 0; 44 }