zoukankan      html  css  js  c++  java
  • bzoj3680 吊打XXX

    Description

    gty又虐了一场比赛,被虐的蒟蒻们决定吊打gty。gty见大势不好机智的分出了n个分身,但还是被人多势众的蒟蒻抓住了。蒟蒻们将n个gty吊在n根绳子上,每根绳子穿过天台的一个洞。这n根绳子有一个公共的绳结x。吊好gty后蒟蒻们发现由于每个gty重力不同,绳结x在移动。蒟蒻wangxz脑洞大开的决定计算出x最后停留处的坐标,由于他太弱了决定向你求助。不计摩擦,不计能量损失,由于gty足够矮所以不会掉到地上。

    Input

    输入第一行为一个正整数n(1<=n<=10000),表示gty的数目。
    接下来n行,每行三个整数xi,yi,wi,表示第i个gty的横坐标,纵坐标和重力。
    对于20%的数据,gty排列成一条直线。
    对于50%的数据,1<=n<=1000。
    对于100%的数据,1<=n<=10000,-100000<=xi,yi<=100000

    Output

    输出1行两个浮点数(保留到小数点后3位),表示最终x的横、纵坐标。

    Sample Input

    3
    0 0 1
    0 2 1
    1 1 1

    Sample Output

    0.577 1.000

    正解:模拟退火算法。

    从此以后我也是退火神教的一员了2333。

    学习模拟退火,请找ACdreamer:http://blog.csdn.net/acdreamers/article/details/10019849

    这道题是经典的费马点问题,然后可以使用模拟退火算法求解。

    模拟退火算法相当于是爬山算法的改进。爬山算法就是每次找到更优解以后直接往更优解走,而模拟退火则是以一定概率接受产生解。而这个概率依赖于当前解与产生解的差值和当前温度。温度越来越低时,因为答案越来越稳定,接受产生解的概率也就越小。

    然后一顿乱搞,多$rand$几次就行了。。

     1 //It is made by wfj_2048~
     2 #include <algorithm>
     3 #include <iostream>
     4 #include <complex>
     5 #include <cstring>
     6 #include <cstdlib>
     7 #include <cstdio>
     8 #include <vector>
     9 #include <cmath>
    10 #include <queue>
    11 #include <stack>
    12 #include <map>
    13 #include <set>
    14 #include <ctime>
    15 #define eps (1e-9)
    16 #define il inline
    17 #define RG register
    18 #define ll long long
    19 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
    20 
    21 using namespace std;
    22 
    23 struct node{ double g,x,y; }p[10010],ans;
    24 
    25 double mans;
    26 int n;
    27 
    28 il double dis(RG node p,RG node q){
    29     return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
    30 }
    31 
    32 il double judge(RG node now){
    33     RG double re=0;
    34     for (RG int i=1;i<=n;++i)
    35     re+=p[i].g*dis(now,p[i]);
    36     if  (re<mans) mans=re,ans=now;
    37     return re;
    38 }
    39 
    40 il double Rand(){ return rand()%1000/1000.0; }
    41 
    42 il void SA(RG double T){
    43     RG node now=ans;
    44     while (T>0.001){
    45     RG node neo;
    46     neo.x=now.x+T*(Rand()*2-1);
    47     neo.y=now.y+T*(Rand()*2-1);
    48     RG double de=judge(now)-judge(neo);
    49     if (de>eps || exp(de/T)>Rand()) now=neo;
    50     T*=0.97;
    51     }
    52     for (RG int i=1;i<=1000;++i){
    53     RG node now;
    54     now.x=ans.x+T*(Rand()*2-1);
    55     now.y=ans.y+T*(Rand()*2-1);
    56     judge(now);
    57     }
    58     return;
    59 }
    60 
    61 il void work(){
    62     cin>>n; mans=1e100;
    63     for (RG int i=1;i<=n;++i){
    64     scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].g);
    65     ans.x+=p[i].x,ans.y+=p[i].y;
    66     }
    67     ans.x/=n,ans.y/=n; judge(ans); SA(1000000);
    68     printf("%0.3lf %0.3lf",ans.x,ans.y); return;
    69 }
    70 
    71 int main(){
    72     File("gty");
    73     srand(233);
    74     work();
    75     return 0;
    76 }
  • 相关阅读:
    asp window.showModalDialog浏览器不兼容的解决方案
    JavaScript倒计时算法(计算剩余多少天)实现
    (全程图解)Axure RP8.0安装教程
    HTML通过超链接传递参数到JSP页面-html与jsp交互
    JavaWeb中登录验证码生成
    PowerDesigner16.5安装教程
    前台正则的使用
    稀疏算法Sparse
    ajax请求超时解决方案
    修改默认select样式
  • 原文地址:https://www.cnblogs.com/wfj2048/p/6632020.html
Copyright © 2011-2022 走看看