zoukankan      html  css  js  c++  java
  • codeforces 617C 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 nx1, 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^2+r2^2的最小值;

    AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    const int N=2003;
    long long x1,x2,y3,y2,x[N],y[N],r1[N],r2[N];
    int main()
    {
        int n;
        long long ans1=0,ans2=0;
        long long ans=0xfffffffffffffff;
        scanf("%d",&n);
        cin>>x1>>y3>>x2>>y2;
        for(int i=1;i<=n;i++)
        {
            cin>>x[i]>>y[i];
            r1[i]=(x[i]-x1)*(x[i]-x1)+(y[i]-y3)*(y[i]-y3);
            r2[i]=(x[i]-x2)*(x[i]-x2)+(y[i]-y2)*(y[i]-y2);
        }
        for(int i=1;i<=n;i++)
        {
            ans1=r1[i];
            ans2=0;
            for(int j=1;j<=n;j++)
            {
                if(r1[j]<=ans1)
                {
                    continue;
                }
                else
                {
                    ans2=max(r2[j],ans2);
                }
            }
            ans=min(ans,ans1+ans2);
        }
        for(int i=1;i<=n;i++)
        {
            ans2=r2[i];
            ans1=0;
            for(int j=1;j<=n;j++)
            {
                if(r2[j]<=ans2)continue;
                else ans1=max(r1[j],ans1);
            }
            ans=min(ans,ans1+ans2);
        }
        cout<<ans<<"
    ";
        return 0;
    }

  • 相关阅读:
    关于 token
    windows 使用 virtualbox,搭建 minikube 环境
    kafka 和 rocketMQ 的数据存储
    分享周鸿祎的《如何建立一个“铁打的营盘”》
    How to configue session timeout in Hive
    毕业十年纪念
    常用排序算法
    [异常处理]class kafka.common.UnknownTopicOrPartitionException (kafka.server.ReplicaFetcherThread)
    线程的几个状态
    星型模式
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5158499.html
Copyright © 2011-2022 走看看