/***************
Problem from : ds
Solve way :
当作是一条线上有n个点
将n个点划分成两个部分 使得这两个部分的长度的平方和 最小
如
有十个点 (S表示圆心1 E表示圆心2
(D表示到圆心1的距离 , d表示到圆心2的距离 )
S 1 2 3 4 5 | 6 7 8 9 10 E (已按D从小到大排序)
如果从第5个点切下去
那么 Sum = D5*D5 + d (max) * d(max)
d (max) = 6 - 10这五点中距离E的最大的距离 (这样才能容纳这五个点)
data:2016.12.6
****************/
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<ctime>
#include<cstring>
#include<vector>
#include<string>
#define ll __int64
#define inf 0x3f3f3f3f3f
using namespace std;
struct node{
int d1;
int d2;
}d[100005];
bool cmp(node a, node b){
return a.d1 < b.d1;
}
int main()
{
int i, n, x, y, x1, x2, y1, y2, ans, tm;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d %d", &x, &y);
d[i].d1 = (x1-x)*(x1-x) + (y1 - y)*(y1 - y);//该点到圆心1的距离
d[i].d2 = (x2-x)*(x2-x) + (y2 - y)*(y2 - y);//该点到圆心2的距离
}
sort(d+1, d+1+n, cmp);//排序
tm = -1, ans = 0x3f3f3f3f;
for(i=n; i>0; i--) //D从大到小去选择
{
tm = (tm>d[i+1].d2)?tm:d[i+1].d2; //取被选择过的点中d的最大值 tm为到圆心2的距离
ans = (ans<d[i].d1+tm)?ans:(d[i].d1+tm);//当前选择的点所产生的ans
}
printf("%d\n", ans);
return 0;
}
ds 5.2 Missile
最新推荐文章于 2025-05-01 14:17:45 发布