1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
题意:是否存在一条光线通过弯曲的管道,不行的话输出能到达最远的横坐标 思路:枚举每两个点,然后判断 #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm> const int maxn = 1e2 + 10; const double eps = 1e-8; const double INF = (double)1e9; using namespace std; //加法误差 double add(double a, double b) { if (fabs(a + b) < eps) return 0; return a + b; } //向量运算 struct P { double x, y; P() {} P(double x, double y) : x(x), y(y) {} void input() { scanf( "%lf %lf" , &x, &y); } P operator + (P p) { return P(add(x, p.x), add(y, p.y)); } P operator - (P p) { return P(add(x, -p.x), add(y, -p.y)); } P operator * (double d) { return P(x * d, y * d); } //点乘 bool operator != (P p) { return add(x, -p.x) || add(y, -p.y); } double dot(P p) { return add(x * p.x, y * p.y); } //叉乘 double det(P p) { return add(x * p.y, -y * p.x); } //是否平行 bool ispar(P q) { P p(x, y); return p.det(q) == 0; } //点是否在线段上 bool onseg(P p1, P p2) { P p(x, y); return (p - p1).det(p - p2) == 0 && (p - p1).dot(p - p2) <= 0; } }; //直线p1-p2 和 q1-q2 交点(有时需要特判线段共线) P in (P p1, P p2, P q1, P q2) { return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1)); } struct Seg { P p, q; Seg() {} Seg(P p, P q) : p(p), q(q) {} }; Seg line[4], seg[maxn]; P f[5]; int main() { int T, n; while (scanf( "%d" , &n) && n) { for (int i = 0; i < n; i++) { seg[i].p.input(); seg[i].q.x = seg[i].p.x; seg[i].q.y = seg[i].p.y - 1; } int sign = 1; double maxx = -INF; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { //四个方向 + 四条直线 line[0] = Seg(seg[j].p, seg[i].p); line[1] = Seg(seg[j].p, seg[i].q); line[2] = Seg(seg[j].q, seg[i].p); line[3] = Seg(seg[j].q, seg[i].q); for (int k = 0; k < 4; k++) { sign = 1; for (int ind = 0; ind < n; ind++) { if (ind == i || ind == j) continue ; P ja = in (seg[ind].p, seg[ind].q, line[k].p, line[k].q); double lf = (seg[ind].p - ja).dot(seg[ind].q - ja); if (lf > 0) { if (ind) { P p1 = in (seg[ind].p, seg[ind - 1].p, line[k].p, line[k].q); P p2 = in (seg[ind].q, seg[ind - 1].q, line[k].p, line[k].q); if (p1.onseg(seg[ind].p, seg[ind - 1].p)) maxx = max(maxx, p1.x); if (p2.onseg(seg[ind].q, seg[ind - 1].q)) maxx = max(maxx, p2.x); } else maxx = max(maxx, seg[ind].p.x); sign = 0; break ; } } if (sign) break ; } if (sign) break ; } if (sign) break ; } if (sign) printf( "Through all the pipe.\n" ); else printf( "%.2f\n" , maxx); } return 0; } |
POJ 1039 Pipe
最新推荐文章于 2020-03-09 10:37:03 发布