LC 1515. Best Position for a Service Centre (Simulated Annealing)

link
LC 1515. Best Position for a Service Centre (Simulated Annealing)_第1张图片

class Solution {
public:
    int n;
    double eps=1E-6;
    const int dx[4]={-1,0,1,0};
    const int dy[4]={0,1,0,-1};
    double getMinDistSum(vector>& positions) {
        n=positions.size();
        double xavg=0.0;
        double yavg=0.0;
        for(auto& p:positions){
            xavg+=p[0];
            yavg+=p[1];
        }
        xavg/=n;
        yavg/=n;
        double mindis=dist(xavg,yavg,positions);
        double step=100.0;
        int done=0;
        while(step>eps){
            done=0;
            for(int i=0;i<4;i++){
                double nx=xavg+step*dx[i];
                double ny=yavg+step*dy[i];
                
                double t=dist(nx,ny,positions);
                if(t>& positions){
        double ret=0.0;
        for(int i=0;i

你可能感兴趣的:(LC 1515. Best Position for a Service Centre (Simulated Annealing))