设为首页 加入收藏

TOP

uva 11178 - Morley's Theorem(训练指南)
2015-11-21 01:21:47 来源: 作者: 【 】 浏览:7
Tags:uva 11178 Morley' Theorem 训练 指南

思路:这题注意练习一下向量的旋转,和直线的相交。

注意代码中用vector表示向量,用point表示点,这一点还是非常好的。

今天是六一儿童节哈,在图书馆A题,呵呵。

?

[cpp]
#include ??
#include ??
#include ??
#include ??
#include ??
using namespace std;?
?
struct point {?
??? double x;?
??? double y;?
??? point(double x = 0, double y = 0) : x(x), y(y) {}?
};?
?
typedef point Vector;?
?
Vector operator - (point A, point B) {?
??? return point(A.x-B.x, A.y-B.y);?
}?
?
Vector operator + (Vector A, Vector B) {?
??? return Vector(A.x+B.x, A.y+B.y);?
}?
?
const double eps = 1e-10;?
int dcmp(double x) {?
??? if(fabs(x) < eps) return 0;?
??? if(x > 0) return 1;?
??? return -1;?
}?
?
double Dot(Vector A, Vector B) {?
??? return A.x*B.x + A.y*B.y;?
}?
?
double Length(Vector A) {?
??? return sqrt(Dot(A, A));?
}?
?
double Cross(Vector A, Vector B) {?
??? return A.x*B.y - A.y*B.x;?
}?
?
Vector operator * (Vector A, double p) {?
??? return Vector(A.x*p, A.y*p);?
}?
?
double Angle(Vector A, Vector B) {?
??? return acos((Dot(A, B))/Length(A)/Length(B));?
}?
?
Vector Rotate(Vector A, double rad) {?
??? return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));?
}?
//调用前确保两条直线相交。当且仅当Cross(v,w)非零。??
point GetLineIntersection(point P, Vector v, point Q, Vector w) {?
??? Vector u = P - Q;?
??? double t = Cross(w, u)/Cross(v, w);?
??? return P + v*t;?
}?
?
point read_point() {?
??? point tmp;?
??? scanf("%lf%lf", &tmp.x, &tmp.y);?
??? return tmp;?
}?
?
point getD(point A, point B, point C) {?
??? Vector v1 = C - B, v2 = A - B;?
??? double a1 = Angle(v1, v2); //两个向量的夹角。??
??? v1 = Rotate(v1, a1/3); //逆时针旋转,弧度.??
?
??? Vector v3 = A - C, v4 = B - C;?
??? double a3 = Angle(v3, v4);?
??? v3 = Rotate(v3, a3*2/3);?
??? return GetLineIntersection(B, v1, C, v3);//求直线的交点.??
}?
?
int main()?
{?
??? int T;?
??? point A, B, C, D, E, F;?
??? scanf("%d", &T);?
??? while(T--) {?
??????? A = read_point();?
??????? B = read_point();?
??????? C = read_point();?
??????? D = getD(A, B, C);?
??????? E = getD(B, C, A);?
??????? F = getD(C, A, B);?
??????? printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n", D.x, D.y, E.x, E.y, F.x, F.y);?
??? }?
??? return 0;?
}?
/**
测试数据:
21
1 1 2 2 1 2
0 0 100 0 50 50
?
1.316987 1.816987 1.183013 1.683013 1.366025 1.633975
56.698730 25.000000 43.301270 25.000000 50.000000 13.397460
**/?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 3686 The Windy's 下一篇hdu1025-Constructing Roads In J..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: