CodeForces - 617C.Watering Flowers ( 枚举

Watering Flowers

题目描述

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.

输入

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.

输出

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

样例

2 -1 0 5 3
0 2
5 2
6

4 0 0 5 0
9 4
8 3
-1 0
1 4
33

题意

给 两个圆 一群点 问全部覆盖后 两个圆的半径平方和 r12+r22 最小

2e3的数据 直接 O(N2) 暴力枚举就可以了 但是 要注意 有可能所有的点都在第二个圆里面 所以我们要先将第二个圆扫一遍 ( 一直wa7 去看了看数据才发现这个问题emmm

AC代码

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))

const int MAXN = 1e5+111;
const LL INFLL = ~0ull>>1;
struct node
{
    LL x, y;
}a, b;
node C[MAXN];
LL dis(node a, node b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
// O(n^2)算法求最长
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n >> a.x >> a.y >> b.x >> b.y;
    for(int i = 1; i <= n; i++) cin >> C[i].x >> C[i].y;
    LL x, x1, x2;
    LL res = INFLL;
    for(int i = 0; i <= n; i++) {
        x = 0;
        x1 = dis(C[i],a);
        if(i == 0) x1 = 0;
        for(int j = 1; j <= n; j++) {
            if(i == j) continue;
            x2 = dis(C[j],a);   //cout << x2 << endl;
           if(x2 <= x1) continue;
            x = max(dis(C[j],b),x);
          //  cout << dis(C[j],b) << " " << x <<endl;
        }
        res = min(res,x+x1);
    }
    cout << res << endl;


return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值