P1337 [JSOI2004] balance point/amputated xxx

Source: Internet
Author: User

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/Output sampleInput Sample # #:
30 0 10 2 11 1 1
Sample # # of output:
0.577 1.000
Description

[Jsoi]

Solution:

  Simulated annealing of the subject bare (the Assistant is really annoying!) )。

  In simple terms, annealing is randomization, if the solution of the random value of the current optimization of the selection of random values, when compared with the current escorted has a certain probability will choose to move the direction of the difference, and when moving beyond a certain limit may appear better solution.

Then this parameter is really complex, our t must be large enough, but after many iterations, each time I tried the thief, chose $0.99$, and then T change rate $r$ I chose $0.95$.

Finally, after the end of the iteration and then run a few times, random the optimal solution.

The tune is over anyway.

Code:

1#include <bits/stdc++.h>2#include <ctime>3 #defineIl inline4 #definell Long Long5 #definefor (I,A,B) for (int (i) = (a);(i) <= (b);(i) + +)6 #defineBor (I,A,B) for (int (i) = (b);(i) >= (a);(i)--)7 #defineMax (a) (a) > (b)? ( A):(B))8 #defineMin (a) > (b) ( b):(a))9 using namespacestd;Ten Const intn=10005; One intN; A Doublew[n],minn=9223372036854775807.0, t=1000000, r=0.995; - structnode{ -     Doublex, y; the }A[N],NOW,ANS,TP; -  -IlDoubleRand () {returnRAND ()%10000/10000.0;} -  +IlDoubleSolve (node tp) { -     Doubleret=0; +for (I,1, N) ret+=w[i]*sqrt ((tp.x-a[i].x) * (tp.x-a[i].x) + (TP.Y-A[I].Y) * (tp.y-a[i].y)); A     if(Ret<minn) ans=tp,minn=ret; at     returnret; - } -  - intMain () { -Srand2336666); -Cin>>N; infor (I,1, N) scanf ("%LF%LF%LF", &a[i].x,&a[i].y,&w[i]), now.x+=a[i].x,now.y+=a[i].y; -Now.x/=n,now.y/=N; to solve (now); +for (I,1,Ten){ -t=6000000; the          while(t>0.001){ *tp.x=now.x+t* (Rand () +rand ()-0.99); $tp.y=now.y+t* (Rand () +rand ()-0.99);Panax Notoginseng             DoubleDe=solve (now)-solve (TP); -             if(de>0|| Exp (de/t) >rand ()) now=TP; thet=t*R; +         } A     } thefor (I,1,5200){ +tp.x=ans.x+t* (Rand () +rand ()-0.99); -tp.y=ans.y+t* (Rand () +rand ()-0.99); $ solve (TP); $     } -printf"%.3LF%.3LF", ans.x,ans.y); -     return 0; the}

P1337 [JSOI2004] balance point/amputated xxx

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.