zoukankan      html  css  js  c++  java
  • cf340 C. Watering Flowers

    C. Watering Flowers
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A flowerbed has many flowers and two fountains.

    You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.

    You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.

    Input

    The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000,  - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.

    Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower.

    It is guaranteed that all n + 2 points in the input are distinct.

    Output

    Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.

    Sample test(s)
    Input
    2 -1 0 5 3
    0 2
    5 2
    Output
    6
    Input
    4 0 0 5 0
    9 4
    8 3
    -1 0
    1 4
    Output
    33
    Note

    The first sample is (r12 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32):

    思路:直接枚举就可以了,r1可以是0或者是到其他任意一个点的距离,然后就枚举r2,条件是到1的距离大于r1中最大,

    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    using namespace std;
    const long long INF = 10e18;
    const int MAX = 2000 + 10;
    long long Distance1[MAX],Distance2[MAX];
    long long get_distance(long long x1,long long y1,long long x2, long long y2)
    {
        return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
    }
    int main()
    {
        int n;
        long long x1,x2,y1,y2,x,y;
        long long r1 = 0,r2 = 0;
        long long ans = INF;
        scanf("%d%I64d%I64d%I64d%I64d", &n,&x1,&y1,&x2,&y2);
        Distance1[0] = Distance2[0] = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%I64d%I64d",&x,&y);
            Distance1[i] = get_distance(x1,y1,x,y);
            Distance2[i] = get_distance(x2,y2,x,y);
        }
    
        for(int i = 0; i <= n; i++)
        {
            r1 = Distance1[i];
            r2 = 0;
            for(int j = 1; j <= n; j++)
            {
                if(Distance1[j] > r1 && Distance2[j] > r2)
                {
                    r2 = Distance2[j];
                }
            }
            ans = min(ans, r1 + r2);
        }
    
        printf("%I64d
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    POJ NOI0113-05 素数回文数的个数(PKU2928)
    POJ NOI0113-04 垂直直方图(PKU2800)
    POJ NOI0113-03 八进制小数(PKU2765)
    UVALive2245 POJ1131 HDU1376 ZOJ1086 Octal Fractions【进制】
    HDU2708 Vertical Histogram
    POJ2136 Vertical Histogram【打印图案】
    POJ2190 HDU2714 ISBN
    POJ NOI0113-02 不吉利日期(PKU2723)
    POJ NOI0113-01 数制转换(PKU2710)
    POJ NOI MATH-7828 最大公约数与最小公倍数
  • 原文地址:https://www.cnblogs.com/zhaopAC/p/5155265.html
Copyright © 2011-2022 走看看