codeforces round#522-D-Barcelonian Distance

In this problem we consider a very simplified model of Barcelona city.

Barcelona can be represented as a plane with streets of kind x=cx=c and y=cy=c for every integer cc (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Diagonal which can be represented as a the set of points (x,y)(x,y) for which ax+by+c=0ax+by+c=0.

One can walk along streets, including the avenue. You are given two integer points AAand BB somewhere in Barcelona. Find the minimal possible distance one needs to travel to get to BB from AA.

Input

The first line contains three integers aa, bb and cc (−109≤a,b,c≤109−109≤a,b,c≤109, at least one of aa and bb is not zero) representing the Diagonal Avenue.

The next line contains four integers x1x1, y1y1, x2x2 and y2y2 (−109≤x1,y1,x2,y2≤109−109≤x1,y1,x2,y2≤109) denoting the points A=(x1,y1)A=(x1,y1) and B=(x2,y2)B=(x2,y2).

Output

Find the minimum possible travel distance between AA and BB. Your answer is considered correct if its absolute or relative error does not exceed 10−610−6.

Formally, let your answer be aa, and the jury's answer be bb. Your answer is accepted if and only if |a−b|max(1,|b|)≤10−6|a−b|max(1,|b|)≤10−6.

Examples

Input

扫描二维码关注公众号,回复: 4336708 查看本文章
1 1 -3
0 3 3 0

Output

4.2426406871

Input

3 1 -9
0 3 3 -1

Output

6.1622776602

Note

The first example is shown on the left picture while the second example us shown on the right picture below. The avenue is shown with blue, the origin is shown with the black dot.

解交点,然后暴力跑一下

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double,double> pll;///(x,y)->x,y
double a,b,c;///ax+by+c=0
pll x1,x2;
double o2(double x){return x*x;}///x^2
double Dist(pll x1,pll x2){///sqrt(x^2+y^2)
    return sqrt(o2(x1.first-x2.first)+o2(x1.second-x2.second));
}
double dist(pll x1,pll x2){///abs(△x)+abs(△y)
    return fabs(x1.first-x2.first)+fabs(x1.second-x2.second);
}
int main(){
    cin>>a>>b>>c;
    cin>>x1.first>>x1.second>>x2.first>>x2.second;///(x,y),(x,y)
    pll A[] = {{x1.first,-(a*x1.first+c)/b},{-(b*x1.second+c)/a,x1.second}};///第一个点,竖线,横线,与之交点
    pll B[] = {{x2.first,-(a*x2.first+c)/b},{-(b*x2.second+c)/a,x2.second}};///第二个点,竖线,横线,与之交点
    double ans = dist(x1,x2);
    for(int i=0;i<2;i++)for(int j=0;j<2;j++)
        ans = min(ans,dist(x1,A[i])+Dist(A[i],B[j])+dist(x2,B[j]));///x1->A->B->x2
    printf("%.10f\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Du_Mingm/article/details/84337943
今日推荐