This documentation is automatically generated by competitive-verifier/competitive-verifier
// clang-format off
// competitive-verifier: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B
// clang-format on
// competitive-verifier: ERROR 0.00000001
#include <complex>
#include <iomanip>
#include <iostream>
#include "../../geometry/convex_polygon_diameter.hpp"
using namespace std;
using namespace geometry;
int main() {
cout << fixed << setprecision(10);
int N;
cin >> N;
Polygon p(N);
for (int i = 0; i < N; i++) {
cin >> p[i];
}
auto ret = convex_polygon_diameter(p);
cout << abs(p[ret.first] - p[ret.second]) << "\n";
}
#line 1 "test/verify/aoj-cgl-4-b.test.cpp"
// clang-format off
// competitive-verifier: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B
// clang-format on
// competitive-verifier: ERROR 0.00000001
#include <complex>
#include <iomanip>
#include <iostream>
#line 2 "geometry/convex_polygon_diameter.hpp"
#include <algorithm>
#line 5 "geometry/convex_polygon_diameter.hpp"
#include <utility>
#line 2 "geometry/point.hpp"
#include <cmath>
#line 6 "geometry/point.hpp"
#include <vector>
#line 2 "geometry/base.hpp"
#line 4 "geometry/base.hpp"
namespace geometry {
using Real = double;
const Real EPS = 1e-8;
const Real PI = std::acos(static_cast<Real>(-1));
enum { OUT, ON, IN };
inline int sign(const Real& r) { return r <= -EPS ? -1 : r >= EPS ? 1 : 0; }
inline bool equals(const Real& a, const Real& b) { return sign(a - b) == 0; }
} // namespace geometry
#line 9 "geometry/point.hpp"
namespace geometry {
using Point = std::complex<Real>;
std::istream& operator>>(std::istream& is, Point& p) {
Real a, b;
is >> a >> b;
p = Point(a, b);
return is;
}
std::ostream& operator<<(std::ostream& os, const Point& p) {
return os << std::real(p) << " " << std::imag(p);
}
Point operator*(const Point& p, const Real& d) {
return Point(std::real(p) * d, std::imag(p) * d);
}
// rotate point p counterclockwise by theta rad
Point rotate(Real theta, const Point& p) {
return Point(std::cos(theta) * std::real(p) - std::sin(theta) * std::imag(p),
std::sin(theta) * std::real(p) + std::cos(theta) * std::imag(p));
}
Real cross(const Point& a, const Point& b) {
return std::real(a) * std::imag(b) - std::imag(a) * std::real(b);
}
Real dot(const Point& a, const Point& b) {
return std::real(a) * std::real(b) + std::imag(a) * std::imag(b);
}
bool compare_x(const Point& a, const Point& b) {
return equals(std::real(a), std::real(b)) ? std::imag(a) < std::imag(b)
: std::real(a) < std::real(b);
}
bool compare_y(const Point& a, const Point& b) {
return equals(std::imag(a), std::imag(b)) ? std::real(a) < std::real(b)
: std::imag(a) < std::imag(b);
}
using Points = std::vector<Point>;
} // namespace geometry
#line 2 "geometry/polygon.hpp"
#line 4 "geometry/polygon.hpp"
#line 6 "geometry/polygon.hpp"
namespace geometry {
using Polygon = std::vector<Point>;
using Polygons = std::vector<Polygon>;
} // namespace geometry
#line 9 "geometry/convex_polygon_diameter.hpp"
namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B
std::pair<int, int> convex_polygon_diameter(const Polygon& p) {
int N = (int)p.size();
int is = 0, js = 0;
for (int i = 1; i < N; i++) {
if (std::imag(p[i]) > std::imag(p[is])) is = i;
if (std::imag(p[i]) < std::imag(p[js])) js = i;
}
Real maxdis = std::norm(p[is] - p[js]);
int maxi, maxj, i, j;
i = maxi = is;
j = maxj = js;
do {
if (cross(p[(i + 1) % N] - p[i], p[(j + 1) % N] - p[j]) >= 0) {
j = (j + 1) % N;
} else {
i = (i + 1) % N;
}
if (std::norm(p[i] - p[j]) > maxdis) {
maxdis = std::norm(p[i] - p[j]);
maxi = i;
maxj = j;
}
} while (i != is || j != js);
return std::minmax(maxi, maxj);
}
} // namespace geometry
#line 11 "test/verify/aoj-cgl-4-b.test.cpp"
using namespace std;
using namespace geometry;
int main() {
cout << fixed << setprecision(10);
int N;
cin >> N;
Polygon p(N);
for (int i = 0; i < N; i++) {
cin >> p[i];
}
auto ret = convex_polygon_diameter(p);
cout << abs(p[ret.first] - p[ret.second]) << "\n";
}
| Env | Name | Status | Elapsed | Memory |
|---|---|---|---|---|
| g++ | 00_sample_00 |
|
3 ms | 4 MB |
| g++ | 00_sample_01 |
|
2 ms | 4 MB |
| g++ | 00_sample_02 |
|
2 ms | 4 MB |
| g++ | 01_small_00 |
|
2 ms | 4 MB |
| g++ | 01_small_01 |
|
2 ms | 4 MB |
| g++ | 01_small_02 |
|
2 ms | 4 MB |
| g++ | 01_small_03 |
|
2 ms | 4 MB |
| g++ | 01_small_04 |
|
2 ms | 4 MB |
| g++ | 03_rand_00 |
|
2 ms | 4 MB |
| g++ | 03_rand_01 |
|
2 ms | 4 MB |
| g++ | 03_rand_02 |
|
2 ms | 4 MB |
| g++ | 03_rand_03 |
|
2 ms | 4 MB |
| g++ | 03_rand_04 |
|
2 ms | 4 MB |
| g++ | 03_rand_05 |
|
2 ms | 4 MB |
| g++ | 03_rand_06 |
|
2 ms | 4 MB |
| g++ | 04_radial_00 |
|
3 ms | 4 MB |
| g++ | 04_radial_01 |
|
4 ms | 4 MB |
| g++ | 05_maximum_00 |
|
11 ms | 4 MB |
| g++ | 05_maximum_01 |
|
11 ms | 4 MB |
| g++ | 06_linear_00 |
|
3 ms | 4 MB |
| g++ | 06_linear_01 |
|
12 ms | 4 MB |
| g++ | 06_linear_02 |
|
6 ms | 4 MB |
| g++ | 06_linear_03 |
|
69 ms | 5 MB |
| g++ | 06_linear_04 |
|
25 ms | 4 MB |
| clang++ | 00_sample_00 |
|
3 ms | 4 MB |
| clang++ | 00_sample_01 |
|
2 ms | 4 MB |
| clang++ | 00_sample_02 |
|
2 ms | 4 MB |
| clang++ | 01_small_00 |
|
2 ms | 4 MB |
| clang++ | 01_small_01 |
|
2 ms | 4 MB |
| clang++ | 01_small_02 |
|
2 ms | 4 MB |
| clang++ | 01_small_03 |
|
2 ms | 4 MB |
| clang++ | 01_small_04 |
|
2 ms | 4 MB |
| clang++ | 03_rand_00 |
|
2 ms | 4 MB |
| clang++ | 03_rand_01 |
|
2 ms | 4 MB |
| clang++ | 03_rand_02 |
|
2 ms | 4 MB |
| clang++ | 03_rand_03 |
|
2 ms | 4 MB |
| clang++ | 03_rand_04 |
|
2 ms | 4 MB |
| clang++ | 03_rand_05 |
|
2 ms | 4 MB |
| clang++ | 03_rand_06 |
|
2 ms | 4 MB |
| clang++ | 04_radial_00 |
|
3 ms | 4 MB |
| clang++ | 04_radial_01 |
|
4 ms | 4 MB |
| clang++ | 05_maximum_00 |
|
11 ms | 4 MB |
| clang++ | 05_maximum_01 |
|
12 ms | 4 MB |
| clang++ | 06_linear_00 |
|
2 ms | 4 MB |
| clang++ | 06_linear_01 |
|
11 ms | 4 MB |
| clang++ | 06_linear_02 |
|
6 ms | 4 MB |
| clang++ | 06_linear_03 |
|
77 ms | 5 MB |
| clang++ | 06_linear_04 |
|
27 ms | 4 MB |