This documentation is automatically generated by online-judge-tools/verification-helper
// competitive-verifier: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A
#include "../../template/template.hpp"
#include "../../geometry/convex_hull.hpp"
using namespace geometry;
int main() {
int N;
cin >> N;
Polygon p(N);
for(auto &s : p) cin >> s;
p = convex_hull(p, false);
N = (int) p.size();
cout << N << "\n";
int idx = 0;
for(int i = 1; i < N; i++) {
if(compare_y(p[i], p[idx])) {
idx = i;
}
}
for(int i = 0; i < N; i++) {
cout << fixed << setprecision(0) << p[(idx + i) % N] << "\n";
}
}
#line 1 "test/verify/aoj-cgl-4-a.test.cpp"
// competitive-verifier: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A
#line 1 "template/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v) is >> in;
return is;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T = int64>
vector<T> make_v(size_t a) {
return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t) fill_v(e, v);
}
template <typename F>
struct FixPoint : F {
explicit FixPoint(F &&f) : F(forward<F>(f)) {}
template <typename... Args>
decltype(auto) operator()(Args &&...args) const {
return F::operator()(*this, forward<Args>(args)...);
}
};
template <typename F>
inline decltype(auto) MFP(F &&f) {
return FixPoint<F>{forward<F>(f)};
}
#line 4 "test/verify/aoj-cgl-4-a.test.cpp"
#line 2 "geometry/base.hpp"
namespace geometry {
using Real = double;
const Real EPS = 1e-8;
const Real PI = 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 3 "geometry/point.hpp"
namespace geometry {
using Point = complex<Real>;
istream &operator>>(istream &is, Point &p) {
Real a, b;
is >> a >> b;
p = Point(a, b);
return is;
}
ostream &operator<<(ostream &os, const Point &p) {
return os << real(p) << " " << imag(p);
}
Point operator*(const Point &p, const Real &d) {
return Point(real(p) * d, imag(p) * d);
}
// rotate point p counterclockwise by theta rad
Point rotate(Real theta, const Point &p) {
return Point(cos(theta) * real(p) - sin(theta) * imag(p),
sin(theta) * real(p) + cos(theta) * imag(p));
}
Real cross(const Point &a, const Point &b) {
return real(a) * imag(b) - imag(a) * real(b);
}
Real dot(const Point &a, const Point &b) {
return real(a) * real(b) + imag(a) * imag(b);
}
bool compare_x(const Point &a, const Point &b) {
return equals(real(a), real(b)) ? imag(a) < imag(b) : real(a) < real(b);
}
bool compare_y(const Point &a, const Point &b) {
return equals(imag(a), imag(b)) ? real(a) < real(b) : imag(a) < imag(b);
}
using Points = vector<Point>;
} // namespace geometry
#line 2 "geometry/polygon.hpp"
#line 4 "geometry/polygon.hpp"
namespace geometry {
using Polygon = vector<Point>;
using Polygons = vector<Polygon>;
} // namespace geometry
#line 4 "geometry/convex_hull.hpp"
namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A
Polygon convex_hull(Polygon &p, bool strict = true) {
int n = (int)p.size(), k = 0;
if (n <= 2) return p;
sort(begin(p), end(p), compare_x);
vector<Point> ch(2 * n);
auto check = [&](int i) {
return sign(cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1])) <= -1 + strict;
};
for (int i = 0; i < n; ch[k++] = p[i++]) {
while (k >= 2 && check(i)) --k;
}
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = p[i--]) {
while (k >= t && check(i)) --k;
}
ch.resize(k - 1);
return ch;
}
} // namespace geometry
#line 6 "test/verify/aoj-cgl-4-a.test.cpp"
using namespace geometry;
int main() {
int N;
cin >> N;
Polygon p(N);
for(auto &s : p) cin >> s;
p = convex_hull(p, false);
N = (int) p.size();
cout << N << "\n";
int idx = 0;
for(int i = 1; i < N; i++) {
if(compare_y(p[i], p[idx])) {
idx = i;
}
}
for(int i = 0; i < N; i++) {
cout << fixed << setprecision(0) << p[(idx + i) % N] << "\n";
}
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++ | 00_sample_00.in | AC | 6 ms | 4 MB |
g++ | 01_small_00.in | AC | 6 ms | 4 MB |
g++ | 01_small_01.in | AC | 6 ms | 4 MB |
g++ | 01_small_02.in | AC | 6 ms | 4 MB |
g++ | 01_small_03.in | AC | 6 ms | 4 MB |
g++ | 02_medium_00.in | AC | 6 ms | 4 MB |
g++ | 02_medium_01.in | AC | 6 ms | 4 MB |
g++ | 02_medium_02.in | AC | 6 ms | 4 MB |
g++ | 02_medium_03.in | AC | 6 ms | 4 MB |
g++ | 03_rand_00.in | AC | 6 ms | 4 MB |
g++ | 03_rand_01.in | AC | 6 ms | 4 MB |
g++ | 03_rand_02.in | AC | 6 ms | 4 MB |
g++ | 03_rand_03.in | AC | 6 ms | 4 MB |
g++ | 04_large_00.in | AC | 26 ms | 6 MB |
g++ | 04_large_01.in | AC | 43 ms | 8 MB |
g++ | 05_radial_00.in | AC | 15 ms | 4 MB |
g++ | 05_radial_01.in | AC | 21 ms | 5 MB |
g++ | 05_radial_02.in | AC | 28 ms | 6 MB |
g++ | 05_radial_03.in | AC | 42 ms | 8 MB |
g++ | 06_linear_00.in | AC | 7 ms | 4 MB |
g++ | 06_linear_01.in | AC | 17 ms | 4 MB |
g++ | 06_linear_02.in | AC | 10 ms | 4 MB |
g++ | 06_linear_03.in | AC | 87 ms | 7 MB |
g++ | 06_linear_04.in | AC | 31 ms | 5 MB |
clang++ | 00_sample_00.in | AC | 6 ms | 4 MB |
clang++ | 01_small_00.in | AC | 6 ms | 4 MB |
clang++ | 01_small_01.in | AC | 6 ms | 4 MB |
clang++ | 01_small_02.in | AC | 6 ms | 4 MB |
clang++ | 01_small_03.in | AC | 6 ms | 4 MB |
clang++ | 02_medium_00.in | AC | 6 ms | 4 MB |
clang++ | 02_medium_01.in | AC | 6 ms | 4 MB |
clang++ | 02_medium_02.in | AC | 6 ms | 4 MB |
clang++ | 02_medium_03.in | AC | 6 ms | 4 MB |
clang++ | 03_rand_00.in | AC | 6 ms | 4 MB |
clang++ | 03_rand_01.in | AC | 6 ms | 4 MB |
clang++ | 03_rand_02.in | AC | 6 ms | 4 MB |
clang++ | 03_rand_03.in | AC | 6 ms | 4 MB |
clang++ | 04_large_00.in | AC | 26 ms | 6 MB |
clang++ | 04_large_01.in | AC | 43 ms | 8 MB |
clang++ | 05_radial_00.in | AC | 15 ms | 4 MB |
clang++ | 05_radial_01.in | AC | 21 ms | 5 MB |
clang++ | 05_radial_02.in | AC | 28 ms | 6 MB |
clang++ | 05_radial_03.in | AC | 42 ms | 8 MB |
clang++ | 06_linear_00.in | AC | 6 ms | 4 MB |
clang++ | 06_linear_01.in | AC | 17 ms | 4 MB |
clang++ | 06_linear_02.in | AC | 10 ms | 4 MB |
clang++ | 06_linear_03.in | AC | 84 ms | 7 MB |
clang++ | 06_linear_04.in | AC | 30 ms | 5 MB |