This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A
// competitive-verifier: ERROR 0.00000001
#include "../../template/template.hpp"
#include "../../geometry/projection.hpp"
using namespace geometry;
int main() {
Line l;
cin >> l;
int Q;
cin >> Q;
while(Q--) {
Point p;
cin >> p;
cout << projection(l, p) << "\n";
}
}
#line 1 "test/verify/aoj-cgl-1-a.test.cpp"
// competitive-verifier: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A
// competitive-verifier: ERROR 0.00000001
#line 1 "template/template.hpp"
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
#endif
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(std::forward<F>(f)) {}
template <typename... Args>
decltype(auto) operator()(Args &&...args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
template <typename F>
inline decltype(auto) MFP(F &&f) {
return FixPoint<F>{std::forward<F>(f)};
}
#line 5 "test/verify/aoj-cgl-1-a.test.cpp"
#line 2 "geometry/projection.hpp"
#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 3 "geometry/line.hpp"
namespace geometry {
struct Line {
Point a, b;
Line() = default;
Line(const Point &a, const Point &b) : a(a), b(b) {}
Line(const Real &A, const Real &B, const Real &C) { // Ax+By=C
if (equals(A, 0)) {
assert(!equals(B, 0));
a = Point(0, C / B);
b = Point(1, C / B);
} else if (equals(B, 0)) {
a = Point(C / A, 0);
b = Point(C / A, 1);
} else if (equals(C, 0)) {
a = Point(0, C / B);
b = Point(1, (C - A) / B);
} else {
a = Point(0, C / B);
b = Point(C / A, 0);
}
}
friend ostream &operator<<(ostream &os, Line &l) {
return os << l.a << " to " << l.b;
}
friend istream &operator>>(istream &is, Line &l) { return is >> l.a >> l.b; }
};
using Lines = vector<Line>;
} // namespace geometry
#line 5 "geometry/projection.hpp"
namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A
Point projection(const Line &l, const Point &p) {
auto t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
return l.a + (l.a - l.b) * t;
}
} // namespace geometry
#line 7 "test/verify/aoj-cgl-1-a.test.cpp"
using namespace geometry;
int main() {
Line l;
cin >> l;
int Q;
cin >> Q;
while(Q--) {
Point p;
cin >> p;
cout << projection(l, p) << "\n";
}
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++ | 00_int_00.in | AC | 6 ms | 4 MB |
g++ | 00_int_01.in | AC | 5 ms | 4 MB |
g++ | 00_int_02.in | AC | 5 ms | 4 MB |
g++ | 00_int_03.in | AC | 5 ms | 4 MB |
g++ | 00_int_04.in | AC | 5 ms | 4 MB |
g++ | 00_int_05.in | AC | 5 ms | 4 MB |
g++ | 01_real_00.in | AC | 5 ms | 4 MB |
g++ | 01_real_01.in | AC | 5 ms | 4 MB |
g++ | 02_online_00.in | AC | 5 ms | 4 MB |
g++ | 02_online_01.in | AC | 5 ms | 4 MB |
g++ | 02_online_02.in | AC | 5 ms | 4 MB |
g++ | 02_online_03.in | AC | 5 ms | 4 MB |
g++ | 03_horizontal_00.in | AC | 5 ms | 4 MB |
g++ | 03_horizontal_01.in | AC | 5 ms | 4 MB |
g++ | 04_vertical_00.in | AC | 5 ms | 4 MB |
g++ | 04_vertical_01.in | AC | 5 ms | 4 MB |
g++ | 05_rand_00.in | AC | 5 ms | 4 MB |
g++ | 05_rand_01.in | AC | 5 ms | 4 MB |
g++ | 05_rand_02.in | AC | 5 ms | 4 MB |
g++ | 05_rand_03.in | AC | 6 ms | 4 MB |
g++ | 05_rand_04.in | AC | 6 ms | 4 MB |
g++ | 05_rand_05.in | AC | 6 ms | 4 MB |
g++ | 05_rand_06.in | AC | 6 ms | 4 MB |
g++ | 05_rand_07.in | AC | 6 ms | 4 MB |
g++ | 05_rand_08.in | AC | 6 ms | 4 MB |
g++ | 05_rand_09.in | AC | 6 ms | 4 MB |
g++ | 05_rand_10.in | AC | 6 ms | 4 MB |
g++ | 05_rand_11.in | AC | 6 ms | 4 MB |
g++ | 05_rand_12.in | AC | 6 ms | 4 MB |
g++ | 05_rand_13.in | AC | 6 ms | 4 MB |
g++ | 05_rand_14.in | AC | 6 ms | 4 MB |
g++ | 05_rand_15.in | AC | 6 ms | 4 MB |
clang++ | 00_int_00.in | AC | 5 ms | 4 MB |
clang++ | 00_int_01.in | AC | 5 ms | 4 MB |
clang++ | 00_int_02.in | AC | 5 ms | 4 MB |
clang++ | 00_int_03.in | AC | 5 ms | 4 MB |
clang++ | 00_int_04.in | AC | 5 ms | 4 MB |
clang++ | 00_int_05.in | AC | 5 ms | 4 MB |
clang++ | 01_real_00.in | AC | 5 ms | 4 MB |
clang++ | 01_real_01.in | AC | 5 ms | 4 MB |
clang++ | 02_online_00.in | AC | 5 ms | 4 MB |
clang++ | 02_online_01.in | AC | 5 ms | 4 MB |
clang++ | 02_online_02.in | AC | 5 ms | 4 MB |
clang++ | 02_online_03.in | AC | 5 ms | 4 MB |
clang++ | 03_horizontal_00.in | AC | 5 ms | 4 MB |
clang++ | 03_horizontal_01.in | AC | 5 ms | 4 MB |
clang++ | 04_vertical_00.in | AC | 5 ms | 4 MB |
clang++ | 04_vertical_01.in | AC | 5 ms | 4 MB |
clang++ | 05_rand_00.in | AC | 5 ms | 4 MB |
clang++ | 05_rand_01.in | AC | 5 ms | 4 MB |
clang++ | 05_rand_02.in | AC | 5 ms | 4 MB |
clang++ | 05_rand_03.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_04.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_05.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_06.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_07.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_08.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_09.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_10.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_11.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_12.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_13.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_14.in | AC | 6 ms | 4 MB |
clang++ | 05_rand_15.in | AC | 6 ms | 4 MB |