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