Title Description
There are n heavy weights, each of which is tied to a rope long enough. Each rope goes from top to bottom through a hole in the table and then ties together. In the figure x is the common knot. Assuming that the rope is fully elastic (without causing energy loss), the table is high enough (so that the weight does not drop to the ground) and ignores all friction.
Ask the knot x where the final balance is.
Note: The holes on the desktop are much smaller than the knot x, so even if a weight is particularly heavy, the knot X is not likely to fall through a hole in the table, at most, at a hole.
Input/output format
Input format:
The first behavior of a file is a positive integer n (1≤n≤1000), which represents the number of weights and holes. The next n rows, each line is 3 integers: Xi.Yi.Wi, which represents the coordinates of the I-hole and the weight of the first heavy. ( -10000≤x,y≤10000, 0<w≤1000)
Output format:
Your program must output two floating-point numbers (three digits after the decimal point), indicating the horizontal and vertical coordinates of the knot x when it is in the final equilibrium state. Two numbers are separated by a space.
Input and Output sample input sample #: Copy
30 0 10 2 11 1 1
Output Example # #: Replication
0.577 1.000
Description
[Jsoi]
It's actually a physics problem qwq ...
We need the point, must be the total energy of the smallest point, where the total energy, is the sum of the gravitational potential energy of each point, if let a point of gravitational potential energy reduce, then pull its rope should be as long as possible, then the table on the rope should be as short as possible
so we need to find a point that makes $\sum_{1}^{n} d[i]*w[i]$ minimum ($d [i]$ represents the distance to the equilibrium point, $w [i]$ represents the weight of that point]
So we can obviously use simulated annealing to find this point.
But the positive solution is not simulated annealing,
There's probably a couple of places to be aware of when annealing.
1.$\delta t$ to set a little bigger,
2. The distance to move needs to be temperature-related
And then without the brain annealing, you can.
Pro-Test time seeds with 19260817 can be
#include <cstdio>#include<cmath>#include<ctime>#include<cstdlib>#defineRand (T) t* ((rand () <<1)-Rand_max)Const intMAXN = 1e6 +Ten;Const DoubleEPS = 1e- -;using namespaceStd;inlineintRead () {Charc = GetChar ();intx =0, F =1; while(C <'0'|| C >'9') {if(c = ='-') F =-1; c =GetChar ();} while(c >='0'&& C <='9') {x = x *Ten+ C-'0'; c =GetChar ();} returnX *F;}intN;structPoint {Doublex, Y, W;} A[MAXN];DoubleAverx,avery;DoubleCalcDoubleXDoubley) {DoubleAns =0; for(inti =1; I <= N; i++) ans+ = sqrt ((x-a[i].x) * (x-a[i].x) + (Y-A[I].Y) * (Y-A[I].Y)) *A[I].W; returnans;}intMain () {Srand (19260817); N=read (); for(inti =1; I <= N; i++) scanf ("%LF%LF%LF", &a[i].x, &A[I].Y, &a[i].w), Averx+ = a[i].x, AverY + =a[i].y; Averx/= N; AverY/=N; DoubleBest = Calc (Averx, AverY), Bestx = Averx, Besty =AverY; DoubleDelatt =0.98; intTime =Ten; while(time--) { Doublenow = Calc (Averx, AverY), nowx = Averx, Nowy =AverY; for(DoubleT =1000000; T > EPS; T *=Delatt) { DoubleWx = nowx + Rand (T), Wy = Nowy +Rand (T); Doublewould =Calc (Wx, Wy); if(Would < best) Best = would, Bestx = Wx, Besty =Wy; if('LL < now | | (exp ((will-now)/T) * Rand_max <rand ())) now= would, nowx = Wx, Nowy =Wy; }} printf ("%.3LF%.3LF", BESTX, besty); return 0;}
Rokua P1337 [JSOI2004] balance point/amputated xxx (simulated annealing)