您的位置:首页 > 其它

bzoj3689 luogu p1337

2015-11-13 18:16 155 查看
人生第一道退火 (虽然调了一个上午然后删了几个变量居然A了雾。

带权值费马点? 反正直接暴力退火就是了 然后不停调常数我可怜的ratioQAQ

附代码:#include
#include
#include
#include
#include
using namespace std;

struct node{
double x,y,g;
}p[10201];
int n;
node ans;
doubleminans=6666666666666666ll;
double dis(nodea,node b)
{
returnsqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double RA()
{
returnrand()00/1000.0;
}
double calc( node t)
{
int i;
double res=0;
for(i=1;i<=n;i++)
res+=dis(p[i],t)*p[i].g;
if(res
minans=res,ans=t;
return res;
}

voidSA(double T)
{
int i;node ne;
node now=ans;
while(T>0.001)
{
ne.x=now.x+T*(RA()*2-1 );
ne.y=now.y+T*(RA()*2-1 );
doublead=calc(now)-calc(ne);
if(ad>0||exp(ad/T)>RA())
now=ne;
T*=0.993;
}
for(i=1;i<=1000;i++)
{
node ne;
ne.x=ans.x+T*(RA()*2-1);
ne.y=ans.y+T*(RA()*2-1);
calc(ne);
}
}

int main()
{
int i;
srand(233666);
scanf("%d",&n);
for(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;
SA(1000000);
//calc((node){0.570,1});
printf("%.3lf%.3lf\n",ans.x,ans.y);

return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: