1 UVa 11178 Morley's Theorem

复制代码
 1 #include <iostream>  
 2 #include <cstdio>  
 3 #include <cstring>  
 4 #include <cstdlib>  
 5 #include <algorithm>  
 6 #include <queue>  
 7 #include <vector>  
 8 #include <stack>  
 9 #include <map>  
10 #include <set>  
11 #include <cmath>  
12 #include <cctype>  
13 #include <ctime>  
14 #include <cassert>  
15   
16 using namespace std;  
17   
18 #define REP(i, n) for (int i = 0; i < (n); ++i)  
19   
20 struct Point {  
21   double x, y;  
22   Point(double x = 0.0, double y = 0.0):x(x),y(y) {}  
23 };  
24 typedef Point Vector;  
25   
26 const double INF = 1e20;  
27 const double eps = 1e-10;  
28 const double PI = acos(-1.0);  
29 Point A, B, C, D, E, F;  
30 int N;  
31   
32 Point operator + (const Point& a, const Vector& b) { return Point{a.x + b.x, a.y + b.y}; }  
33 Vector operator - (const Point& a, const Point& b) { return Vector(a.x - b.x, a.y - b.y); }  
34 Vector operator * (const Vector& a, double k) { return Vector{a.x * k, a.y * k}; }  
35 double dot(const Vector& a, const Vector& b) { return a.x * b.x + a.y * b.y; }  
36 double length(const Vector& a) { return sqrt(dot(a, a)); }  
37 double angle(const Vector& a, const Vector& b) { return acos(dot(a, b) / length(a) / length(b)); }  
38 double cross(const Vector& a, const Vector& b) { return a.x * b.y - a.y * b.x; }  
39 Point read_point() { double x, y; scanf("%lf %lf", &x, &y); return Point{x, y}; }  
40 Point line_intersection(const Point& p, const Vector& v, const Point& q, const Vector& w) {  
41     Vector u = p - q; double t = cross(w, u) / cross(v, w); return p + v * t;  
42 }  
43 Vector rotate(const Vector& a, double rad) {  
44     return Vector{a.x * cos(rad) - a.y * sin(rad), a.x * sin(rad) + a.y * cos(rad)};  
45 }  
46 Point get_D(Point a, Point b, Point c) {  
47     Vector v1 = c - b; double a1 = angle(v1, a - b); v1 = rotate(v1, a1 / 3.0);  
48     Vector v2 = b - c; double a2 = angle(a - c, v2); v2 = rotate(v2, -a2 / 3.0);  
49     return line_intersection(b, v1, c, v2);  
50 }  
51   
52 int main() {  
53 #ifdef __AiR_H  
54     freopen("in.txt", "r", stdin);  
55 //    freopen("out.txt", "w", stdout);  
56 #endif // __AiR_H  
57     scanf("%d", &N);  
58     while (N--) {  
59         A = read_point(); B = read_point(); C = read_point();  
60         D = get_D(A, B, C); E = get_D(B, C, A); F = get_D(C, A, B);  
61         printf("%.6f %.6f %.6f %.6f %.6f %.6f\n", D.x, D.y, E.x, E.y, F.x, F.y);  
62     }  
63 #ifdef __AiR_H  
64     printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);  
65 #endif // __AiR_H  
66     return 0;  
67 }  
View Code
复制代码