Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance

D. Barcelonian Distance

在这里插入图片描述

solution

考虑五种情况,A,B两点与直线的交点两两组合,以及不经过直线的距离

code

/*Siberian Squirrel*/
/*Cute JinFish*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const double PI = acos(-1), eps = 1e-8;
/*const int MOD = 998244353, r = 119, k = 23, g = 3;
const int MOD = 1004535809, r = 479, k = 21, g = 3;*/
const int MOD = 1e9 + 7, INF = 0x3f3f3f3f;
const int N = 2e6 + 10, M = 1e7 + 10;

int sgn(double x) {
    
    
    if(fabs(x) < eps) return 0;
    return x < 0? -1: 1;
}
//inline int rnd(){static int seed=2333;return seed=(((seed*666666ll+20050818)%998244353)^1000000007)%1004535809;}
//double Rand() {return (double)rand() / RAND_MAX;}

int n;
double a, b, c;
struct node{
    
    
    double x, y;
}A, B, C, D, E, F;

void init() {
    
    }

double dis(node a, node b) {
    
    
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

void solve(ll res = 0, double minn = 1.0 * INF, bool f = true) {
    
    
    minn = fabs(A.x - B.x) + fabs(A.y - B.y);

    C.x = A.x, C.y = (-c - a * C.x) / b;
    E.y = A.y, E.x = (-c - b * E.y) / a;

    D.x = B.x, D.y = (-c - a * D.x) / b;
    F.y = B.y, F.x = (-c - b * F.y) / a;

    minn = min(minn, fabs(C.y - A.y) + fabs(D.y - B.y) + dis(C, D));
    minn = min(minn, fabs(C.y - A.y) + fabs(F.x - B.x) + dis(C, F));

    minn = min(minn, fabs(E.x - A.x) + fabs(D.y - B.y) + dis(E, D));
    minn = min(minn, fabs(E.x - A.x) + fabs(F.x - B.x) + dis(E, F));

    cout << fixed << setprecision(10) << minn << endl;
}


int main() {
    
    
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(nullptr);
// srand(time(0));
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    init();
    int o = 1;
//	cin >> o;
    while(o --) {
    
    
        cin >> a >> b >> c;
        cin >> A.x >> A.y >> B.x >> B.y;
        solve();
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_46173805/article/details/115144777
今日推荐