zoukankan      html  css  js  c++  java
  • Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力

    C. Watering Flowers

    题目连接:

    http://www.codeforces.com/contest/617/problem/C

    Descriptionww.co

    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 Input

    2 -1 0 5 3
    0 2
    5 2

    Sample Output

    6

    Hint

    题意

    有一个花园,有两个喷水龙头,你需要浇灌花园里面所有的花

    两个喷水龙头的喷水半径分别是r1,r2

    你需要使得r1*r1+r2*r2最小

    请问是多少

    题解:

    将其中一维排序,然后另外一维直接取剩下的最大值就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    struct node
    {
        long long x,y;
    };
    
    node p[2];
    node point[2005];
    long long pre[2005];
    bool cmp(node a,node b)
    {
        if(a.x==b.x)return a.y<b.y;
        return a.x<b.x;
    }
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=0;i<2;i++)
            scanf("%lld%lld",&p[i].x,&p[i].y);
        for(int i=1;i<=n;i++)
        {
            long long x,y;
            scanf("%lld%lld",&x,&y);
            point[i].x = (x-p[0].x)*(x-p[0].x)+(y-p[0].y)*(y-p[0].y);
            point[i].y = (y-p[1].y)*(y-p[1].y)+(x-p[1].x)*(x-p[1].x);
        }
        sort(point+1,point+1+n,cmp);
        for(int i=n;i>=1;i--)
            pre[i]=max(pre[i+1],point[i].y);
        long long ans = pre[1];
        for(int i=1;i<=n;i++)
            ans = min(ans,point[i].x+pre[i+1]);
        cout<<ans<<endl;
    }
  • 相关阅读:
    常见问题:bootstrap datepicker日期插件汉化
    好的插件
    问题11:web前端开发规范手册(转)
    问题10:获取当前页面宽度JS
    SQL学习1:基础
    问题9:tabtle 整理
    Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space
    测试markdown 博客功能
    Cannot generate SSPI context
    Ubuntu 13 Zookeeper 集群配置
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5156385.html
Copyright © 2011-2022 走看看