zoukankan      html  css  js  c++  java
  • Problem : [Noip2010普及组]导弹拦截

    Problem : [Noip2010普及组]导弹拦截

    Time Limit: 1 Sec Memory Limit: 128 MB

    Description

    经过11 年的韬光养晦,某国研发出了一种新的导弹拦截系统,凡是与它的距离不超过其工作半径的导弹都能够被它成功拦截。当工作半径为0 时,则能够拦截与它位置恰好相同的导弹。但该导弹拦截系统也存在这样的缺陷:每套系统每天只能设定一次工作半径。而当天的使用代价,就是所有系统工作半径的平方和。某天,雷达捕捉到敌国的导弹来袭。由于该系统尚处于试验阶段,所以只有两套系统投入工作。如果现在的要求是拦截所有的导弹,请计算这一天的最小使用代价。

    Input

    第一行包含4 个整数x1、y1、x2、y2,每两个整数之间用一个空格隔开,表示这两套导弹拦截系统的坐标分别为(x1, y1)、(x2, y2)。第二行包含1 个整数N,表示有N 颗导弹。接下来N 行,每行两个整数x、y,中间用一个空格隔开,表示一颗导弹的坐标(x, y)。不同导弹的坐标可能相同。1 ≤ N ≤ 100000,且所有坐标分量的绝对值都不超过1000

    Output

    输出只有一行,包含一个整数,即当天的最小使用代价。
    两个点(x1, y1)、(x2, y2)之间距离的平方是(x1- x2)2+(y1-y2)2。
    两套系统工作半径r1、r2 的平方和,是指r1、r2 分别取平方后再求和,即r12+r22。

    Sample Input

    样例1
    0 0 10 0
    2
    -3 3
    10 0

    样例2
    0 0 6 0
    5
    -4 -2
    -2 3
    4 0
    6 -2
    9 1

    Sample Output

    样例1
    18

    【样例 1 说明】
    样例1 中要拦截所有导弹,在满足最小使用代价的前提下,两套系统工作半径的平方分别为18 和0。

    样例2
    30

    【样例2 说明】
    样例中的导弹拦截系统和导弹所在的位置如下图所示。要拦截所有导弹,在满足最小使用代价的前提下,两套系统工作半径的平方分别为20 和10。

    code:

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    const int maxn=100002,inf=1000000000;
    int X1,Y1,X2,Y2,n;
    struct data {
    	int x,y;
    	long long t1, t2;
    };
    bool cmp(data a,data b){
    	return a.t1<b.t1;
    }
    data d[maxn];
    int main(){
    	scanf("%d %d %d %d",&X1,&Y1,&X2,&Y2);
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++) {
    		scanf("%d %d",&d[i].x,&d[i].y);
    		d[i].t1=(long long)(X1-d[i].x)*(X1-d[i].x)+(long long)(Y1-d[i].y)*(Y1-d[i].y);
    		d[i].t2=(long long)(X2-d[i].x)*(X2-d[i].x)+(long long)(Y2-d[i].y)*(Y2-d[i].y);
    	}
    	sort(d+1,d+n+1,cmp);
    	long long r2=0,ans=inf;
    	for(int i=n;i>0;i--) {
    		r2=max(d[i+1].t2,r2);
    		ans=min(ans,r2+d[i].t1);
    	}
    	printf("%lld",ans);
    	return 0;
    }
    
  • 相关阅读:
    __dict__和dir()的区别:未完
    [leetcode] Subsets II
    [leetcode] Decode Ways
    [leetcode] Gray Code
    [leetcode] Merge Sorted Array
    [leetcode] Partition List
    [leetcode] Scramble String
    [leetcode] Maximal Rectangle
    [leetcode] Remove Duplicates from Sorted List II
    [leetcode] Remove Duplicates from Sorted List
  • 原文地址:https://www.cnblogs.com/ZhaoChongyan/p/11740418.html
Copyright © 2011-2022 走看看