[JSOI2004] Balance Point

Source: Internet
Author: User

Link to original topic
A detailed introduction to simulated annealing can be peng-ym on the introduction of simulated annealing.

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.
Thinking of solving problems
  • This problem is not the only one of the few problems in Oi that are related to physics. (233)
  • The question asks what is the final balance of the knot?
  • According to the knowledge of physics, when the system is in equilibrium, the total energy of the system is minimal.
  • At this time the total energy of the system is equal to the gravitational potential energy of each object, when the quality is certain, that is, the object is nearest to the ground, farthest from the table.
  • So, the distance between the rope and the table is as small as possible. That is:\ (\sum_{i=1}^{n}m_i*dist_{i,x}\) is the smallest.
  • The problem to be solved by simulated annealing is to find the location of this point.
  • The main parameters of simulated annealing are several:\ (t_0\) initial temperature,\ (t\) each drop in temperature,\ (ans\) so far the best answer,\ (now\) new state,\ (delta\) The difference between the current answer and the best answer.
  • There is a small way to extend the state:\ ((rand () *2-randmax) *t\). The principle is that the range of ( rand () *2-randmax) \) is from negative to positive, so that the child can expand in multiple directions when the coordinates are extended, and not be updated in only one direction.
  • (PS: There is also a very important question, the metaphysical assistant.) This kind of problem is best in can see the evaluation result of OJ hand over, otherwise you will not know is oneself the wrong, or the parameter did not adjust well ... )

    Directly on the code:
    #include <bits/stdc++.h>#define Nusing namespaceStdTemplate<TypeNameT>inline voidRead (T &x) {x=0;Static intp;p=1;Static CharC;c=getchar (); while(!isdigit (c)) {if(c=='-') p=-1; C=getchar ();} while(IsDigit (c)) {x= (x<<1) + (x<<3) + (c-48); C=getchar ();} X*=p;}structnode{DoubleX,y,w;} E[n];intNDoubleAnsx,ansy;Const Doubleeps=1e-15;DoubleFDoubleXDoubleY) {Doubletot=0; for(intI=1; i<=n;i++) {Doubledelx=x-e[i].x;DoubleDELY=Y-E[I].Y; Tot+=sqrt (delx*delx+dely*dely) *E[I].W;}returnTot;}voidMnth () {Doublet= $; while(t>eps) {Doublenowx=ansx+ (rand () *2-rand_max) *t;Doublenowy=ansy+ (rand () *2-rand_max) *t;DoubleDelta=f (Nowx,nowy)-F (Ansx,ansy);if(delta<0) Ansx=nowx,ansy=nowy;Else if(exp (-DELTA/T) *rand_max>rand ()) Ansx=nowx,ansy=nowy; t*=0.998;}}intMain () {#ifndef Online_judgeFreopen ("Mnth.in","R", stdin); Freopen ("Mnth.out","W", stdout);#endifSrand ((int) time (NULL)); Read (n); for(intI=1; i<=n;i++) {scanf ("%LF%LF%LF", &AMP;E[I].X,&AMP;E[I].Y,&AMP;E[I].W); ANSX+=E[I].X;ANSY+=E[I].Y;} Ansx/= (Double) n;ansy/= (Double) N;mnth ();p rintf ("%.3LF %.3lf\n", Ansx,ansy);return 0;}

[JSOI2004] Balance Point

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.