zoukankan      html  css  js  c++  java
  • BZOJ 3680 模拟退火

    思路:
    退火就好了……
    1.强烈建议题目名称改为“吊打出题人”
    2.这种题放oj上啥心态。。。—–hzwer

    二分TLE和WA 终于AC了……

    //By SiriusRen
    #include <cmath>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int n,XX=-100001,YY=100001;
    double l,r,w=50000,jyx,jyy;
    struct Point{double x,y,wei;}point[10050],b,ans,t;
    double dis(Point a){
        double res=0;
        for(int i=1;i<=n;i++){
            jyx=(a.x-point[i].x),jyy=(a.y-point[i].y);
            res+=sqrt(jyx*jyx+jyy*jyy)*point[i].wei;
        }return res;
    }
    int main(){
        srand(1005730820),scanf("%d",&n),ans.wei=0x3fffffff;
        for(int i=1;i<=n;i++)scanf("%lf%lf%lf",&point[i].x,&point[i].y,&point[i].wei);
        b.wei=dis(b);
        while(w>1e-4){
            for(int j=1;j<=30;j++){
                double ran=rand();
                t.x=b.x+w*sin(ran),t.y=b.y+w*cos(ran),t.wei=dis(t);
                if(t.x<XX||t.x>YY||t.y<XX||t.y>YY)continue;
                if(t.wei<b.wei)b=t;
            }
            if(b.wei<ans.wei)ans=b;
            w=w*0.9;
        }
        printf("%.3lf %.3lf
    ",t.x,t.y);
    }

    这里写图片描述

  • 相关阅读:
    2020.9.21
    企业应用架构模式003——对象-关系结构模式
    企业应用架构模式002
    企业应用架构模式001
    代码大全003/
    代码大全002/
    每日总结
    数论必刷题
    Tarjan求割点(割顶) 割边(桥)
    Luogu 2018 秋令营 Test 2
  • 原文地址:https://www.cnblogs.com/SiriusRen/p/6532134.html
Copyright © 2011-2022 走看看