Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define fori(n) for (int i = 0; i < (n); i++)
- #define forj(n) for (int j = 0; j < (n); j++)
- #define FOR(a,b,c) for (int a = (b); a < (c); ++a)
- #define forfill(n,x) for (int zzz = 0; zzz < (n); zzz++) cin >> x[zzz]
- #define all(x) (x).begin(), (x).end()
- #define allr(x) (x).rbegin(), (x).rend()
- #define unsync cin.sync_with_stdio(false), cin.tie(0)
- #define inoutfile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
- //scanf("%d",&n);
- #define INFINITY (1e+300*1e+300)
- typedef long long lng;
- typedef pair<int, int> pii;
- typedef pair<lng, lng> pll;
- typedef vector<int> vi;
- typedef vector<vector<int>> vii;
- typedef vector<pair<int, int>> vpii;
- int a, b, c;
- struct point {
- long long x, y;
- };
- point start, endp;
- double dist(point a, point b) {
- double x = a.x - b.x;
- double y = a.y - b.y;
- return sqrt(x*x + y*y);
- }
- int main()
- {
- scanf("%d%d%d", &a, &b, &c);
- scanf("%I64d %I64d %I64d %I64d", &(start.x), &(start.y), &(endp.x), &(endp.y));
- point startLineV;
- point startLineX;
- point endLineV;
- point endLineX;
- startLineV.x = start.x;
- startLineX.y = start.y;
- endLineV.x = endp.x;
- endLineX.y = endp.y;
- double startToLineV = INFINITY, startToLineX = INFINITY, endToLineV = INFINITY, endToLineX = INFINITY;
- startLineV.y = -c - a * startLineV.x;
- if (startLineV.y % b == 0) {
- startLineV.y /= b;
- startToLineV = dist(start, startLineV);
- }
- startLineX.x = -c - b * startLineX.y;
- if (startLineX.x % a == 0) {
- startLineX.x /= a;
- startToLineX = dist(start, startLineX);
- }
- endLineV.y = -c - a * endLineV.x;
- if (endLineV.y % b == 0) {
- endLineV.y /= b;
- endToLineV = dist(endp, endLineV);
- }
- endLineX.x = -c - b * endLineX.y;
- if (endLineX.x % a == 0) {
- endLineX.x /= a;
- endToLineX = dist(endp, endLineX);
- }
- double v[] = {
- startToLineV + endToLineV + dist(startLineV, endLineV),
- startToLineX + endToLineV + dist(startLineX, endLineV),
- startToLineV + endToLineX + dist(startLineV, endLineX),
- startToLineX + endToLineX + dist(startLineX, endLineX),
- abs(start.x -endp.x)+abs(start.y-endp.y)
- };
- printf("%.8lf", *min_element(v, v + 5));
- //y=(-c-ax)/b
- //ax+by+c=0.
- //printf("%d\n", stolen)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement