• HDU 3932 Groundhog Build Home 【基础模拟退火】


    和刚才那道是一模一样

    不过求的是最小的,只要稍微修改一下就可以了~

    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <string>
    #include <map>
    #include <queue>
    #include <vector>
    #include <ctime>
    #include <algorithm>
    #define LL long long
    #define Max(a,b) (((a) > (b)) ? (a) : (b))
    #define Min(a,b) (((a) < (b)) ? (a) : (b))
    #define Abs(x) (((x) > 0) ? (x) : (-(x)))
    #define MOD 1000000007
    #define eps 1e-8
    #define pi acos(-1.0)
    
    using namespace std;
    
    const int inf = 0x3f3f3f3f;
    const int N = 15;
    const int L = 35;
    
    int t,n;
    double X ,Y, best[50];
    
    struct Point{
        double x,y;
        bool check(){
            if(x > -eps && x < eps + X && y > -eps && y < eps + Y)
                return true;
            return false;
        }
    }p[1005],tp[50];
    
    double dist(Point p1,Point p2){
        return sqrt((p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y));
    }
    
    double min_dis(Point p0){
        double ans = 0;//
        for(int i = 0; i < n; ++i)
            ans = max(ans,dist(p[i],p0));//
        return ans;
    }
    
    Point rand_point(double x, double y){
        Point c;
        c.x = (rand() % 1000 + 1) / 1000.0 * x;
        c.y = (rand() % 1000 + 1) / 1000.0 * y;
        return c;
    }
    
    int main(){
        srand(time(NULL));
        while(EOF != scanf("%lf%lf%d",&X,&Y,&n)){
            for(int i = 0; i < n; ++i)
                scanf("%lf%lf",&p[i].x,&p[i].y);
            for(int i = 0; i < N; ++i){
                tp[i] = rand_point(X, Y);
                best[i] = min_dis(tp[i]);
            }
            double step = max(X,Y) / sqrt(1.0 * n);
            while(step > 1e-3){
                for(int i = 0; i < N; ++i){
                    Point cur;
                    Point pre = tp[i];
                    for(int j = 0; j < L; ++j){
                        double angle = (rand() % 1000 + 1) / 1000.0 * 2 * pi;
                        cur.x = pre.x + cos(angle) * step;
                        cur.y = pre.y + sin(angle) * step;
                        if(!cur.check()) continue;
                        double tmp = min_dis(cur);
                        if(tmp < best[i]){//
                            tp[i] = cur;
                            best[i] = tmp;
                        }
                    }
                }
                step *= 0.85;
            }
            int idx = 0;
            for(int i = 0; i < N; ++i){
                if(best[i] < best[idx]){//
                    idx = i;
                }
            }
            printf("(%.1f,%.1f).
    ",tp[idx].x,tp[idx].y);
            printf("%.1f
    ",best[idx]);
        }
        return 0;
    }
  • 相关阅读:
    BZOJ1093: [ZJOI2007]最大半连通子图
    BZOJ4033: [HAOI2015]树上染色
    BZOJ1977: [BeiJing2010组队]次小生成树 Tree
    BZOJ4944: [Noi2017]泳池
    BZOJ1269: [AHOI2006]文本编辑器editor
    BZOJ4596: [Shoi2016]黑暗前的幻想乡
    BZOJ1815: [Shoi2006]color 有色图
    BZOJ1488: [HNOI2009]图的同构
    BZOJ3527: [Zjoi2014]力
    Salazar Slytherin's Locket CodeForces
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4242439.html
Copyright © 2020-2023  润新知