Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define all(a) (a).begin(), (a).end()
- const double pi = 3.14159265;
- struct Point {
- int x, y;
- Point() {}
- Point(int _x, int _y) {
- x = _x;
- y = _y;
- }
- Point operator-(Point &p) const {
- return Point(x - p.x, y - p.y);
- }
- };
- struct Vec {
- int x, y;
- Vec() {}
- Vec(int _x, int _y) {
- x = _x;
- y = _y;
- }
- Vec(Point end) {
- x = end.x;
- y = end.y;
- }
- Vec(Point beg, Point end) {
- x = end.x - beg.x;
- y = end.y - beg.y;
- }
- // scalar
- double operator^(const Vec &v) const {
- return x * v.x + y * v.y;
- }
- // vector
- double operator*(const Vec &v) const {
- return x * v.y - v.x * y;
- }
- double phi2() {
- double a = atan2(y, x);
- if (a < 0)
- a += 2 * pi;
- return a;
- }
- double phi() {
- return atan2(y, x);
- }
- double len() {
- return sqrt(x * x + y * y);
- }
- };
- struct Segment {
- Point a, b;
- Segment() {}
- Segment(Point _a, Point _b) {
- a = _a;
- b = _b;
- }
- };
- double dist(Segment &s, Point &c) {
- Vec ab(s.a, s.b);
- Vec ac(s.a, c);
- Vec bc(s.b, c);
- if ((ac ^ ab) > 0 && (bc ^ ab) < 0)
- return abs((ab * ac) / ab.len());
- return min(ac.len(), bc.len());
- }
- istream& operator>>(istream& in, Point &p) {
- return in >> p.x >> p.y;
- }
- istream& operator>>(istream& in, Vec &v) {
- return in >> v.x >> v.y;
- }
- istream& operator>>(istream& in, Segment &s) {
- return in >> s.a >> s.b;
- }
- void solve() {
- Point a;
- cin >> a;
- Segment s;
- cin >> s;
- cout << dist(s, a) << '\n';
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.setf(ios_base::boolalpha);
- int t = 1;
- // cin >> t;
- while (t--)
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement