题解:P5544 [JSOI2016] 炸弹攻击1

· · 题解

我们考虑模拟退火把这个题操过去。

考虑模拟退火一轮中的贪心,假设我当前随机到了一个点 (x,y),那么我肯定找到当前能够取到的最大的圆,统计这个圆内的点数。

一个很显然的贪心是按照 x=\frac{\sum_{i=1}^m p_i}{m},y = \frac{\sum_{i=1}^m q_i}{m} 跑一遍模拟退火,然后你就会发现有点倒闭。因为对于两个离得比较远的区域来说,如果你进入了一个区域,那么你就出不来了,也就是说你陷入了一个局部最优解,而舍弃了另一个更优的局部最优解。

所以有一个更加好的策略就是:我们在原来的基础上,以每个 (q_i,p_i) 都来跑一遍模拟退火,这样显然能够不漏地遍历每一个局部最优。

然后就做完了。

然后调参,看脸。

:::info[code]

#include<bits/stdc++.h>
using namespace std;
constexpr int N = 11,M = 1e3+1,L = 5;
constexpr long double delta = 0.99,S0 = 1e-3,Se = 4e5,T0 = 2000,Te = 1e-3;
int n,m,R,x[N],y[N],r[N];
struct node{
    int x,y;
}a[M];
set<pair<int,int> >vis;
int ans = 0,nowans;
inline long double dist(const long double &x,const long double &y,const long double &xx,const long double &yy){
    return sqrtl((x-xx)*(x-xx)+(y-yy)*(y-yy));
}
long double mind,dis;
inline int calc(const long double &nowx,const long double &nowy){
    mind = R;
    dis = INT_MAX;
    for(int i = 1;i<=n;++i){
        mind = min(mind,dist(x[i],y[i],nowx,nowy)-r[i]);
    }
    int res = 0;
    for(int i = 1;i<=m;++i){
        long double d = dist(a[i].x,a[i].y,nowx,nowy);
        dis = min(dis,d-mind);
        if(d<=mind){
            ++res;
        }
    }
    return res;
}
inline long double rnd(){
    return rand()*1.0/RAND_MAX;
}
long double t,nowx,nowy;
void SA(){
    t = T0;
    while(t>Te){
        for(int l = 1;l<=L;++l){
            if((long double)clock()/CLOCKS_PER_SEC>=0.95){
                cout << ans;
                exit(0);
            }
            long double ks = log(Se*1.0/S0),kt = log(Te/T0),S1 = S0*pow(t/T0,ks/kt);
            long double lenx = (S0+(S1-S0)*rnd())*((rand()&1)?1:-1);
            long double leny = (S0+(S1-S0)*rnd())*((rand()&1)?1:-1);
            long double newx = nowx+lenx,newy = nowy+leny;
            int newans = calc(newx,newy);
            if(newans>nowans){
                nowx = newx,nowy = newy;
                nowans = newans;
                ans = max(ans,nowans);
            }else{
                if(newans == 0){
                    if(expl((dis/(Se*sqrtl(2))-nowans)*1.0/t)>rnd()){
                        nowx = newx,nowy = newy;
                        nowans = newans;
                        ans = max(ans,nowans);
                    }
                }else if(expl((newans-nowans)*1.0/t)>rnd()){
                    nowx = newx,nowy = newy;
                    nowans = newans;
                    ans = max(ans,nowans);
                }
            }
        }
        t*=delta;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin >> n >> m >> R;
    for(int i = 1;i<=n;++i){
        cin >> x[i] >> y[i] >> r[i];
    }
    for(int i = 1;i<=m;++i){
        cin >> a[i].x >> a[i].y;
        nowx+=a[i].x;
        nowy+=a[i].y;
    }
    nowx/=m,nowy/=m;
    srand(time(0));
    random_shuffle(a+1,a+m+1);
    nowans = max(nowans,calc(nowx,nowy));
    SA();
    for(int i = 1;i<=m;++i){
        if((long double)clock()/CLOCKS_PER_SEC>=0.999){
            break;
        }
        if(vis.count({a[i].x,a[i].y})||rand()%4 == 0){
            continue;
        }
        vis.insert({a[i].x,a[i].y});
        nowans = calc(a[i].x,a[i].y);
        nowx = a[i].x,nowy = a[i].y;
        SA();
    }
    cout << ans;
    return 0;
}

:::