Codeforces 617C Watering Flowers 【暴力 数据范围】

16 篇文章 0 订阅

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 nx1y1x2y2 (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 = 5r22 = 1):The second sample is (r12 = 1r22 = 32):

恩,这题注意数据范围。


#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#define ll __int64
#define INF 0x3f3f3f3f
#define inf 1LL<<63-1
#define maxn 2020
using namespace std;
struct node
{
    ll dis1,dis2;
};
node pin[maxn];
bool cmp(node a,node b)
{
    return a.dis1<b.dis1;
}
ll dis(ll x0,ll y0,ll x,ll y)
{
    return ((x-x0)*(x-x0)+(y-y0)*(y-y0));
}
int main()
{
    int n;
    ll x1,y1,x2,y2,x,y;
    while(~scanf("%d",&n))
    {
        scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2);
        for(int i=1;i<=n;++i)
        {
            scanf("%I64d%I64d",&x,&y);
            pin[i].dis1=dis(x,y,x1,y1);
            pin[i].dis2=dis(x,y,x2,y2);
        }
        pin[0].dis1=0;
        pin[0].dis2=0;
        sort(pin,pin+n+1,cmp);
        ll sum=inf,tem=0;
        for(int i=0;i<=n;++i)
        {
            tem=0;
            for(int j=i+1;j<=n;++j)
                tem=max(tem,pin[j].dis2);
            sum=min(sum,tem+pin[i].dis1);
        }
        if(n==1)
            sum=min(pin[1].dis1,pin[1].dis2);
        printf("%I64d\n",sum);
    }
    return 0;
}
1.  LL 使得整数文字类型 long long 。 所以 2LL ,是一种2型 long long 。 如果没有 LL ,字面只会类型 int 。 这一点很重要,当你做这样的东西:

1 << 40
1LL << 40
只用文字 1 ,(假设 int 为32位,你转移超出了整数类型的大小->未定义的行为)。 同 1LL ,您将类型设置为 long long 前手,现在将正确地返回2 ^ 40。
本文标题 :什么是1LL或2LL在C和C ++?
原文地址 :CodeGo.net/575292/ (关于1LL的原文)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值