考虑一种情况:
当系统A能够包含点p(x,y)
而系统B距离点p更加近,我们会更新系统B,然不需要
by Enthon_Yuan @ 2022-11-14 19:33:19
@[Enthon_Yuan](/user/212382) 谢谢我70了,还有什么可以改进的吗?
```cpp
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int xx1, yy1, xx2, yy2;
int work1, work2;
int n, x, y;
int main()
{
cin >> xx1 >> yy1 >> xx2 >> yy2;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> x >> y;
int dis1 = pow(abs(xx1 - x), 2) + pow(abs(yy1 - y), 2);
int dis2 = pow(abs(xx2 - x), 2) + pow(abs(yy2 - y), 2);
if(work1 >= dis1) continue;
if(work2 >= dis2) continue;
if(dis1 < dis2) //第一个导弹拦截系统更优
work1 = max(work1, dis1);
else
work2 = max(work2, dis2);
}
cout << work1 + work2;
return 0;
}
```
by 卷王 @ 2022-11-14 19:44:22
```cpp
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int xx1, yy1, xx2, yy2;
int work1, work2;
int n, x, y;
int main()
{
cin >> xx1 >> yy1 >> xx2 >> yy2;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> x >> y;
int dis1 = pow(abs(xx1 - x), 2) + pow(abs(yy1 - y), 2);
int dis2 = pow(abs(xx2 - x), 2) + pow(abs(yy2 - y), 2);
if(work1 >= dis1) continue; // 改在这里
if(work2 >= dis2) continue; // 改在这里
if(dis1 < dis2) //第一个导弹拦截系统更优
work1 = max(work1, dis1);
else
work2 = max(work2, dis2);
}
cout << work1 + work2;
return 0;
}
```
by 卷王 @ 2022-11-14 19:45:05
我的意思是,弃这个贪心思路吧。
HACK:
如果我把上文的p(x,y),在前面输入,那么系统1会接纳,然后再输入q(x,y),让系统2,接纳。实际上我们只需要系统2扩大范围就可以了。
### 贪心是没有正确性的。
所以你可以看一看题解什么的。
比如说排序,这个真的很难死磕
by Enthon_Yuan @ 2022-11-14 19:54:26
@[Enthon_Yuan](/user/212382) 知道了thanks
by 卷王 @ 2022-11-14 20:21:21
emmm…………
by 卷王 @ 2022-11-14 20:21:34
@[Enthon_Yuan](/user/212382) [AC](https://www.luogu.com.cn/record/94046993)
by 卷王 @ 2022-11-14 20:24:20
@[holdyhao_Genius](/user/494699) 《反 客 为 主》
by RNTBW @ 2022-11-14 20:48:26
~~让我来出HACK~~
by Enthon_Yuan @ 2022-11-18 17:26:14
**同问**![](//图.tk/8)
```cpp
#include<bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
}l1,l2,a[100010];
int b[100010],c[100010],k1=-1,k2=-1,m1=0,m2=0;
int main()
{
int n;
cin>>l1.x>>l1.y>>l2.x>>l2.y>>n;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
int t1=pow((a[i].x-l1.x),2)+pow((a[i].y-l1.y),2),t2=pow((a[i].x-l2.x),2)+pow((a[i].y-l2.y),2);
if(t1<t2)
b[++k1]=t1,m1=max(m1,t1);
else
c[++k2]=t2,m2=max(m2,t2);
}
printf("%d",m1+m2);
return 0;
}
```
by 123xiayicheng @ 2023-01-02 15:17:16