| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求助大佬,讨论区数据都过了。。。```cpp
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cassert>
using namespace std;
namespace liuzimingc {
#define endl '\n'
const int N = 505;
const double eps = 1e-4;
int T, n;
bool equal(double a, double b = 0) { return fabs(a - b) < eps; }
struct point {
double x, y;
point(double a = 0, double b = 0) { x = a, y = b; }
void input() { scanf("%lf %lf", &x, &y); }
friend point operator +(point a, point b) { return point(a.x + b.x, a.y + b.y); }
friend point operator -(point a, point b) { return point(a.x - b.x, a.y - b.y); }
friend point operator *(point a, double b) { return point(a.x * b, a.y * b); }
friend point operator /(point a, double b) { return point(a.x / b, a.y / b); }
friend double dot(point a, point b) { return a.x * b.x + a.y * b.y; }
friend double operator *(point a, point b) { return a.x * b.y - a.y * b.x; }
friend bool operator ==(point a, point b) { return equal(a.x, b.x) && equal(a.y, b.y); }
} a[N], b[N];
struct segment {
point v[2];
segment(point a = point(0, 0), point b = point(0, 0)) { v[0] = a, v[1] = b; }
void input() { v[0].input(), v[1].input(); }
bool include(point p) {
return equal((v[0] - p) * (v[1] - p)) && dot(v[0] - p, v[1] - p) <= 0;
}
bool intersect(segment s) {
if (equal((v[0] - s.v[0]) * (v[1] - s.v[0])) && equal((v[0] - s.v[1]) * (v[1] - s.v[1]))) {
return include(s.v[0]) || include(s.v[1]);
}
return ((v[1] - v[0]) * (s.v[0] - v[0])) * ((v[1] - v[0]) * (s.v[1] - v[0])) <= 0 && ((s.v[1] - s.v[0]) * (v[0] - s.v[0])) * ((s.v[1] - s.v[0]) * (v[1] - s.v[0])) <= 0;
} // note
double dis() { return sqrt(pow(v[0].x - v[1].x, 2) + pow(v[0].y - v[1].y, 2)); }
};
struct line {
point v[2];
line(point a = point(0, 0), point b = point(0, 0)) { v[0] = a, v[1] = b; }
void input() { v[0].input(), v[1].input(); }
bool include(point p) {
return equal((v[0] - p) * (v[1] - p));
}
bool intersect(segment s) {
return ((v[0] - s.v[0]) * (v[1] - s.v[0])) * ((v[0] - s.v[1]) * (v[1] - s.v[1])) <= 0;
} // note about -1 / 1?
bool fuck(segment s) {
return ((v[0] - s.v[0]) * (v[1] - s.v[0])) * ((v[0] - s.v[1]) * (v[1] - s.v[1])) < 0;
}
bool intersect(line l) {
// return !equal((v[0] - v[1]) * (l.v[0] - l.v[1]));
return (v[0] - v[1]) * (l.v[0] - l.v[1]) < 0;
}
point intersection(line l) {
double s1 = (l.v[0] - v[0]) * (l.v[1] - v[0]), s2 = (l.v[1] - v[1]) * (l.v[0] - v[1]);
return v[0] + (v[1] - v[0]) * s1 / (s1 + s2);
}
};
double get(line l) {
if (!l.intersect(segment(a[1], b[1]))) return -1e18;
for (int i = 2; i <= n; i++) {
if (l.intersect(segment(a[i], b[i]))) continue;
if (l.fuck(segment(a[i], a[i - 1]))) return l.intersection(line(a[i], a[i - 1])).x;
if (l.fuck(segment(b[i], b[i - 1]))) return l.intersection(line(b[i], b[i - 1])).x;
return a[i - 1].x;
}
return a[n].x;
}
int main() {
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
while (~scanf("%d", &n) && n) {
for (int i = 1; i <= n; i++) a[i].input(), b[i] = point(a[i].x, a[i].y - 1);
if (n <= 2) {
puts("Through all the pipe.");
continue;
}
double ans = a[0].x;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
// ans = max(ans, get(line(a[i], a[j])));
ans = max(ans, get(line(a[i], b[j])));
ans = max(ans, get(line(b[i], a[j])));
// ans = max(ans, get(line(b[i], b[j])));
}
if (equal(ans - a[n].x)) puts("Through all the pipe.");
else printf("%.2f\n", ans);
}
return 0;
}
#undef int
} // namespace liuzimingc
int main() {
liuzimingc::main();
return 0;
}
```
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator