Simulated annealing of mountain climbing algorithm

Source: Internet
Author: User

bzoj3680 amputated xxx

Topic: Given some weight on ropes and ropes, find the coordinates of the last knot.

Idea: This position is the generalized fee-for-horse point, which is the point at which all points are located at the lowest weight of each point. Simulated annealing, various modulation constants.

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<cstdlib>#defineMaxnode 10005using namespacestd;structuse{DoubleX,y,gi;} Ai[maxnode]={0},ans;Doubleminn=999999999999999LL;intN;DoubleRan () {returnRAND ()% +/1000.0;}DoubleFangDoubleA) {returnA *A;}DoubleDis (use A,use b) {returnsqrt (Fang (a.x-b.x) +fang (a.y-b.y));}DoubleCalc (use a) {intIDoublej=0;  for(i=1; i<=n;++i) J+=dis (A,ai[i]) *Ai[i].gi; if(J<minn) {minn=j;ans=a;}returnJ;}voidWorkDoublet) {Use A,now=ans;intIDoubleJ;  while(t>0.01) {a.x=now.x+t* (Ran () *2-1); A.Y=now.y+t* (Ran () *2-1); J=calc (now)-Calc (a); if(j>0|| Exp (j/t) >ran ()) now=A; T*=0.980; }     for(i=1; i<= +;++i) {a.x=ans.x+t* (Ran () *2-1); A.Y=ans.y+t* (Ran () *2-1);    Calc (a); }}intMain () {intI,J;SCANF ("%d", &n); Srand (23333);  for(i=1; i<=n;++i) {scanf ("%LF%LF%LF",&ai[i].x,&ai[i].y,&ai[i].gi); Ans.x+=ai[i].x*1.0; ans.y+=ai[i].y*1.0; }ans.x/=n;ans.y/=N; Work (500000);p rintf ("%.3f%.3f\n", ANS.X,ANS.Y);}
View Code

Simulated annealing of mountain climbing algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.