- 这题到底是模拟退火还是爬山
- 为什么样例没过 90 分
- 路过的大佬能帮忙看下怎么改吗
#include <bits/stdc++.h>
using namespace std;
int n,m,r;
int ans;
struct node {
double x,y,z;
} a[15],b[1005];
double rand(double l,double r) {
return double(rand())/RAND_MAX*(r-l)+l;
}
double sq(double x) {
return x*x;
}
double distan(node a,node b) {
return sqrt(sq(a.x-b.x)+sq(a.y-b.y));
}
int calc(node p) {
int res=0;
double dis=r;
for(int i=1; i<=n; i++)
dis=min(dis,distan(p,a[i])-a[i].z);
for(int i=1; i<=m; i++)
if(distan(p,b[i])<=dis)res++;
return res;
}
void sa() {
node p= {rand(-2e4,2e4),rand(-2e4,2e4)};
ans=max(ans,calc(p));
for(double t=2e4; t>1e-18; t*=0.99) {
node np= {rand(p.x-t,p.x+t),rand(p.y-t,p.y+t)};
int dt=calc(np)-calc(p);
ans=max(ans,calc(np));
if(dt>0)p=np;
}
}
int main() {
srand(time(0));
scanf("%d%d%d",&n,&m,&r);
ans=0;
for(int i=1; i<=n; i++)
scanf("%lf %lf %lf",&a[i].x,&a[i].y,&a[i].z);
for(int i=1; i<=m; i++)
scanf("%lf %lf",&b[i].x,&b[i].y);
while(double(clock())/CLOCKS_PER_SEC<=0.8)sa();
printf("%d",ans);
return 0;
}