Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <queue>
- #include <cmath>
- #include <set>
- #include <stack>
- #include <bitset>
- #include <map>
- #ifndef M_PI
- #define M_PI 3.141592653589
- #endif
- //#define int long long
- #define double long double
- #define f(variable, start, end) for (int variable = start; variable < end; ++variable)
- #define be(a) a.begin(), a.end()
- #define no cout << "NO\n"
- #define yes cout << "YES\n"
- #define nor cout << "NO\n"; return
- #define yesr cout << "YES\n"; return
- #define vi vector<int>
- #define vvi vector<vector<int>>
- using namespace std;
- template<typename T, typename E>
- vector<T> &operator>>(vector<T> &v, E a) {
- v.push_back(a);
- return v;
- }
- //abs for any type
- template<typename T>
- T abs(T a) {
- if (0 < a) {
- return a;
- } else {
- return -a;
- }
- }
- //pair output
- template<typename E>
- ostream &operator<<(ostream &os, pair<E, E> &t) {
- os << t.first << ' ' << t.second << '\n';
- return os;
- }
- //"map" pair output
- template<typename E>
- ostream &operator<<(ostream &os, pair<const E, E> &t) {
- os << t.first << ' ' << t.second << '\n';
- return os;
- }
- //vector output
- template<typename T>
- ostream &operator<<(ostream &os, vector<T> &vec) {
- for (T i : vec) {
- os << i << '\n';
- }
- cout << '\n';
- return os;
- }
- //2 dimensional vector output
- template<typename T>
- ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
- for (vector<T> i : vec) {
- os << i;
- }
- return os;
- }
- struct Point {
- double x, y;
- Point() {
- x = 0;
- y = 0;
- }
- double dist(Point a) const {
- return sqrt((a.x - x) * (a.x - x) + (a.y - y) * (a.y - y));
- }
- };
- bool eq(double a, double b) {
- return fabs(a - b) <= 1e-7;
- }
- bool ge(double a, double b) {
- return a > b && !eq(a, b);
- }
- struct Vector {
- double x, y;
- Vector(Point A, Point B) {
- x = B.x - A.x;
- y = B.y - A.y;
- }
- double len() const {
- return sqrt(x * x + y * y);
- }
- double dot_product (Vector a) const {
- return x * a.x + y * a.y;
- }
- double cross_product (Vector a) const {
- return x * a.y - y * a.x;
- }
- };
- istream &operator>>(istream &in, Point &P) {
- in >> P.x >> P.y;
- return in;
- }
- ostream &operator<<(ostream &out, Point &P) {
- out << P.x << " " << P.y;
- return out;
- }
- int32_t main() {
- cin.tie(NULL);
- cout.tie(NULL);
- cout.setf(ios::fixed);
- cout.precision(10);
- ios_base::sync_with_stdio(false);
- Point P, A, B;
- cin >> P >> A >> B;
- Vector AB(A, B);
- Vector BA(B, A);
- Vector AP(A, P);
- Vector BP(B, P);
- if (ge(AB.dot_product(AP), 0) && ge(BA.dot_product(BP), 0))
- cout << fabs(AB.cross_product(AP)) / AB.len() << endl;
- else
- cout << min(P.dist(A), P.dist(B)) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement