您的位置:首页 > 其它

bzoj3680 吊打XXX

2017-03-28 09:41 351 查看

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$几次就行了。。

//It is made by wfj_2048~
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#define eps (1e-9)
#define il inline
#define RG register
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

struct node{ double g,x,y; }p[10010],ans;

double mans;
int n;

il double dis(RG node p,RG node q){
return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
}

il double judge(RG node now){
RG double re=0;
for (RG int i=1;i<=n;++i)
re+=p[i].g*dis(now,p[i]);
if  (re<mans) mans=re,ans=now;
return re;
}

il double Rand(){ return rand()%1000/1000.0; }

il void SA(RG double T){
RG node now=ans;
while (T>0.001){
RG node neo;
neo.x=now.x+T*(Rand()*2-1);
neo.y=now.y+T*(Rand()*2-1);
RG double de=judge(now)-judge(neo);
if (de>eps || exp(de/T)>Rand()) now=neo;
T*=0.97;
}
for (RG int i=1;i<=1000;++i){
RG node now;
now.x=ans.x+T*(Rand()*2-1);
now.y=ans.y+T*(Rand()*2-1);
judge(now);
}
return;
}

il void work(){
cin>>n; mans=1e100;
for (RG int i=1;i<=n;++i){
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].g);
ans.x+=p[i].x,ans.y+=p[i].y;
}
ans.x/=n,ans.y/=n; judge(ans); SA(1000000);
printf("%0.3lf %0.3lf",ans.x,ans.y); return;
}

int main(){
File("gty");
srand(233);
work();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: