zoukankan      html  css  js  c++  java
  • luogu 1337

    这东西真玄学啊。。

    在eps,delta,T之间改来改去。。。

    在wa4,wa6,wa8之间轮转。

    然后就过了。

    爬山考虑合力然后移动即可。

    eps要设的很小才行,布吉岛为森么

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef double db;
     4 const db eps = 1e-14;
     5 const db delta = 0.993;
     6 const db INF = 1e100;
     7 struct point{
     8     db x,y,w;
     9     point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
    10     point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
    11     point operator * (db k1) const{return (point){x*k1,y*k1};}
    12     db abs(){return sqrt(x*x+y*y);}
    13     db dis(point k1){return ((*this)-k1).abs();}
    14 };
    15 point p[1005];int n;
    16 db mxx=1e18;point ans;
    17 void sa(){
    18     db T = 2005;
    19     while (T>eps){
    20         db x=ans.x+(rand()*2-RAND_MAX)*T,y=ans.y+(rand()*2-RAND_MAX)*T;
    21         db z=0;
    22         for(int i=1;i<=n;i++)
    23             z+=sqrt((p[i].x-x)*(p[i].x-x)+(p[i].y-y)*(p[i].y-y))*p[i].w;
    24         if(z<mxx){
    25             mxx=z;
    26             ans={x,y};
    27         }
    28         T*=delta;
    29     }
    30 }
    31 int main(){
    32     scanf("%d",&n);
    33     for(int i=1;i<=n;i++)scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].w);
    34     sa();sa();sa();
    35     printf("%.3f %.3f
    ",ans.x,ans.y);
    36 }
    View Code
  • 相关阅读:
    C#中Linq查询基本操作
    Python中的四种数据结构
    20200917练习题
    SRS搭建自己的直播、点播系统
    20200916练习题
    20200915练习题
    20200914练习题
    20200911练习题
    UTF-8最多编码字符数(最多可以容纳多少数量的字符)?
    k8s新手必看
  • 原文地址:https://www.cnblogs.com/MXang/p/10922082.html
Copyright © 2011-2022 走看看