Codeforces Round #340 (Div. 2) C. Watering Flowers

两种方法,一种n2,一种nlogn

#include <cstdio>
#include <vector>
typedef long long ll;
using namespace std;
ll pow(int a)
{
    return a * (ll) a;
}
int main()
{
    int n, x1, x2, y1, y2;
    scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);
    vector< pair<ll, ll> >vv(n);
    for (int i = 0; i < n; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        vv[i].first = pow(a - x1) + pow(b - y1);
        vv[i].second = pow(a - x2) + pow(b - y2);
    }
    vv.push_back({0, 0});
    ll ans = 1e18;
    for (int i = 0; i <= n; i++)
    {
        ll r1 = vv[i].first;
        ll r2 = 0;
        for (int j = 0; j <= n; j++)
        {
            if (vv[j].first > r1)
            {
                r2 = max(r2, vv[j].second);
            }
        }
        ans = min(r1 + r2, ans);
    }
    printf("%I64d\n", ans);
    return 0;
}


你可能感兴趣的:(Codeforces Round #340 (Div. 2) C. Watering Flowers)