Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //no brain
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <string>
- #include <cmath>
- #include <set>
- #include <unordered_set>
- #include <unordered_map>
- #include <chrono>
- #include <stack>
- #include <cassert>
- #include <queue>
- #include <deque>
- #include <climits>
- #include <cstring>
- #include <random>
- #include <bitset>
- #include <functional>
- using namespace std;
- typedef long double ld;
- const ld inf = 1e9;
- const ld eps = 1e-9;
- struct Point {
- ld x;
- ld y;
- Point() {
- x = -1;
- y = -1;
- }
- Point(ld x_, ld y_) {
- x = x_;
- y = y_;
- }
- friend istream & operator >> (istream & in, Point &p) {
- in >> p.x >> p.y;
- return in;
- }
- friend ostream & operator << (ostream & out, Point &p) {
- out << fixed << setprecision(16) << " " << p.x << " " << p.y << "\n";
- return out;
- }
- ld dist(const Point &other) const{
- return sqrt((x - other.x) * (x - other.x) + (y - other.y) * (y - other.y));
- }
- bool operator != (const Point &other) {
- return x != other.x || y != other.y;
- }
- };
- struct Vector {
- ld x;
- ld y;
- Vector(Point &a, Point &b) {
- x = a.x - b.x;
- y = a.y - b.y;
- }
- Vector(ld x_, ld y_) {
- x = x_;
- y = y_;
- }
- ld operator % (const Vector &other) const{
- return x * other.x + y * other.y;
- }
- ld operator * (const Vector &other) const{
- return x * other.y - other.x * y;
- }
- Vector operator / (ld k) const{
- return Vector(x / k, y / k);
- }
- Vector operator * (ld k) const{
- return Vector(x * k, y * k);
- }
- };
- Point operator + (const Point &tmp, const Vector &other) {
- return Point(tmp.x + other.x, tmp.y + other.y);
- }
- Point intersection(Point a, Point b, Point c, Point d) {
- Vector v(b, a);
- ld s1 = Vector(c, a) * Vector(d, a);
- ld s2 = Vector(d, b) * Vector(c, b);
- ld s = s1 + s2;
- if (fabs(s) < eps) {
- return Point(-inf, -inf);
- }
- v = v / s;
- v = v * s1;
- Point O = a + v;
- return O;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- #ifdef LOCAL
- assert(freopen("input.txt", "r", stdin));
- assert(freopen("output.txt", "w", stdout));
- #endif
- int a, b, c;
- cin >> a >> b >> c;
- int x1, y1, x2, y2;
- cin >> x1 >> y1 >> x2 >> y2;
- Point ff;
- Point ss;
- if (b == 0 || a == 0) {
- cout << abs(x1 - x2) + abs(y1 - y2);
- return 0;
- } else {
- ff = Point(0, -c / b);
- ss = Point(1, -(c + a) / b);
- }
- ld ans = abs(x1 - x2) + abs(y1 - y2);
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < 2; j++) {
- Point f;
- Point s;
- if (i) {
- f = intersection(ff, ss, Point(x1, y1), Point(x1, y1 + 1));
- } else {
- f = intersection(ff, ss, Point(x1, y1), Point(x1 + 1, y1));
- }
- if (j) {
- s = intersection(ff, ss, Point(x2, y2), Point(x2, y2 + 1));
- } else {
- s = intersection(ff, ss, Point(x2, y2), Point(x2 + 1, y2));
- }
- ans = min(ans, f.dist(Point(x1, y1)) + s.dist(Point(x2, y2)) + f.dist(s));
- }
- }
- cout << fixed << setprecision(16) << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement