题解
2023-03-04 17:57:53
发布于:上海
#include<iostream>
#include<algorithm>//sort必须调用的库
using namespace std;
int x1,y1,x2,y2,n;//输入的五个数,为了cmp函数方便使用,开成全局变量
int d[100007];//预处理出来d数组,具体用途请看思路
struct node
{
int x;//记录导弹的位置信息
int y;
}w[100007];
bool cmp(node a,node b)
{
int q=(x1-a.x)(x1-a.x)+(y1-a.y)(y1-a.y);
int p=(x1-b.x)(x1-b.x)+(y1-b.y)(y1-b.y);
return(q<p);
}
int main(){
int ans=0;
cin>>x1>>y1>>x2>>y2;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>w[i].x>>w[i].y;
}
sort(w,w+n,cmp);
for(int i=n-1;i>=0;i--)
{
int h=(x2-w[i].x)(x2-w[i].x)+(y2-w[i].y)(y2-w[i].y);//预处理过程
d[i]=max(d[i+1],h);
}
ans=d[0];
for(int i=0;i<n;i++)
{
int cnt=0;
cnt=(x1-w[i].x)(x1-w[i].x)+(y1-w[i].y)(y1-w[i].y);
cnt+=d[i+1];//由于d[i]所保留的最大值包括i,而此时i属于前缀
ans=min(ans,cnt);
}
ans=min(ans,d[0]);
cout<<ans;
return 0;
}
全部评论 2
编译错误: /code/judger/test/1836735141092229120/main.cpp: In function 'bool cmp(node, node)':
/code/judger/test/1836735141092229120/main.cpp:13:22: error: expression cannot be used as a function
int q=(x1-a.x)(x1-a.x)+(y1-a.y)(y1-a.y);
^
/code/judger/test/1836735141092229120/main.cpp:13:39: error: expression cannot be used as a function
int q=(x1-a.x)(x1-a.x)+(y1-a.y)(y1-a.y);
^
/code/judger/test/1836735141092229120/main.cpp:14:22: error: expression cannot be used as a function
int p=(x1-b.x)(x1-b.x)+(y1-b.y)(y1-b.y);
^
compilation terminated due to -fmax-errors=3.2024-09-19 来自 天津
0/code/judger/run/4966585417741631586/main11.cpp: In function 'bool cmp(node, node)':
/code/judger/run/4966585417741631586/main11.cpp:13:22: error: expression cannot be used as a function
int q=(x1-a.2024-03-24 来自 浙江
0
有帮助,赞一个