POJ 1039 Pipe
来源:互联网 发布:制作相片软件下载 编辑:程序博客网 时间:2024/05/01 04:23
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;
}
0 0
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- poj 1039 Pipe
- POJ 1039 pipe
- POJ 1039--Pipe
- poj 1039 Pipe
- Pipe - POJ 1039 几何
- POJ 1039 Pipe
- poj 1039 Pipe
- POJ-1039-Pipe
- POJ 1039 Pipe
- poj 1039 Pipe
- java treeset实现不重复存储的方式(在类对象中实例化CompareTo)
- 共享可变性设计中存在风险以及解决方法(二)
- Android中插件开发篇之----动态加载Activity(免安装运行程序)
- 电脑输入ipconfig 出现:"ipconfig不是内部或外部命令",怎么造成的?
- 堆排序
- POJ 1039 Pipe
- MSVCP110.dll丢失修复办法
- centos配置https(nginx,apache)
- Codeigniter 无法记录终止性错误和异常解决办法
- 写第个一项目的时候的入门级错误
- Joty and Chocolate
- 循环神经网络(RNN, Recurrent Neural Networks)介绍
- Struts2请求加上时间戳出现java.lang.NumberFormatException: For input string:
- Android加载大位图之压缩图片像素和质量参数