bzoj3689 luogu p1337

   人生第一道退火  (虽然调了一个上午然后删了几个变量居然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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值