Bzoj 3680: amputated xxx "simulated annealing algorithm bare topic learning, mountain climbing algorithm Learning"

Source: Internet
Author: User

3680: amputated xxx time limit:10 Sec Memory limit:128 mbsec Special Judge
submit:3192 solved:1198
[Submit] [Status] [Discuss] Description

Gty and abused a game, the battered Konjac Konjac decided amputated gty. Gty See the trend is not good wit out of n a fen, but still be numbers Konjac Konjac caught. Konjac Konjac will
n a gty hanging on n ropes, each rope passing through a hole in the roof. This n-string has a common knot x. After hanging good gty Konjac Konjac found that because each gty gravity is different, the rope
Knot x is moving. Konjac Konjac WANGXZ The decision to calculate the coordinates of the last stop, because he was too weak to ask you for help.
No friction, no energy loss, because the gty is short enough so will not fall to the ground.

Input

Enter the first behavior a positive integer n (1<=n<=10000) that represents the number of gty.
The next n lines, three integers per line, represent the xi,yi,wi of the gty, the ordinate and the gravity of the first.
For 20% of the data, the gty is arranged in a straight line.
For 50% of data, 1<=n<=1000.
For 100% of data, 1<=n<=10000,-100000<=xi,yi<=100000

Output

Outputs 1 rows of two floating-point numbers (reserved to 3 digits after the decimal point), indicating the horizontal and vertical axis of the final x.

Sample Input3
0 0 1
0 2 1
1 1 1
Sample Output0.577 1.000
Hintsource


by Wangxz

Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=3680

Analysis: I was killed anyway, this question who told me is water problem,!!!!! Simulated annealing algorithm-----advanced, mountain climbing algorithm------Just heard of Qaq today, OK, learn, after all, is a bare question ~ ~ ~

The main topic: given n a particle, the center of gravity, this n the center of gravity to meet σ (center of Gravity point I distance) *g[i] The smallest, simulated annealing of the naked problem, the INF open 0x3f properly ... At least to max_of _long_long near can!

Idea:puts ("Nan nan"); Ac//bzoj seems to be this way, a lot of problems such as writing will be AC

Climbing is enough, simulated annealing is also possible.

Simulated annealing is the simulation of an annealing process, the difference between him and the mountain is that it has a temperature parameter.

We can see that the more we get to the back, the closer we get. So we should change the scope of the change is smaller, the likelihood of accepting the inferior solution should also be small.

So we introduce a temperature variable t, the membrane you anneal the process, the temperature gradually drops.

The following is a procedure for simulating annealing:

Set the initial high temperature T

While temperature > Minimum value set

A new solution is obtained randomly (the higher the temperature, the greater the difference between the new solution and the old solution)

Update answer

According to the good and bad relationship between the new solution and the old solution, accept the new solution with a certain probability (the more advantageous is possible)

Cool down in a certain way

Endwhile

In order to ensure the quality of the answer, we can then do random near the optimal solution and update the answer

The simulated annealing code is as follows: "The code runs very slowly and slowly." 10000ms+ "

1#include <bits/stdc++.h>2 using namespacestd;3 Const intm=10010;4 structNode5 {6     Doublex,y,g;7 }point[m],ans;8 intN;9 Doubleminans=1e100;TenInlineDoubleDisConstNode &a,ConstNode &b) One { A     returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); - } -InlineDoubleJudgeConstNode &p) the { -     inti; -     DoubleRe=0; -      for(i=1; i<=n;i++) +     { -re+=point[i].g*dis (p,point[i]); +     } A     if(re<Minans) at     { -ans=p; -minans=re; -     } -     returnre; - } inInlineDoubleRand () - { to     returnRAND ()% +/1000.0; + } -InlinevoidSA (DoubleT) the { *     inti; $Node now=ans;Panax Notoginseng      while(t>0.001) -     { the Node Neo; +neo.x=now.x+t* (Rand () *2-1); Aneo.y=now.y+t* (Rand () *2-1); the         DoubleDe=judge (now)-judge (Neo); +         if(de>0|| Exp (de/t) >Rand ()) -now=Neo; $t*=0.993; $     } -      for(i=1; i<= +; i++) -     { the Node Neo; -neo.x=ans.x+t* (Rand () *2-1);Wuyineo.y=ans.y+t* (Rand () *2-1); the judge (Neo); -     } Wu } - intMain () About { $     inti; -Srand19980805); -Cin>>N; -      for(i=1; i<=n;i++) A     { +scanf"%LF%LF%LF",&point[i].x,&point[i].y,&point[i].g); theans.x+=point[i].x; -ans.y+=point[i].y; $     } theAns.x/=N; theAns.y/=N; theSA (1000000); theprintf"%.3LF%.3lf\n", ans.x,ans.y); -     return 0; in}

The mountain climbing algorithm code is as follows "Fast 8000ms+"

1#include <bits/stdc++.h>2 using namespacestd;3 intN;4 DoubleAnsx,ansy;5 structData6 {7     Doublex, y;8     intW;9}p[10005];TenInlineDoubleSqrDoublex) One { A     returnx*x; - } -InlineDoubleDisDoubleXDoubleY,data p) the { -     returnsqrt (SQR (x-p.x) +sqr (yp.y)); - } - voidhillclimb () + { -      Doublet= +, x, y; +       for(intI=1; i<=n;i++) Aansx+=p[i].x*p[i].w,ansy+=p[i].y*P[I].W; atAnsx/=N; -Ansy/=N; -       while(t>0.00000001) -      { -x=y=0; -           for(intI=1; i<=n;i++) in          { -x+= (P[I].X-ANSX) *p[i].w/dis (ansx,ansy,p[i]); toy+= (P[i].y-ansy) *p[i].w/dis (ansx,ansy,p[i]); +          } -ansx+=x*t;ansy+=y*T; the          if(t>0.5) t*=0.5; *          Elset*=0.97; $      }Panax Notoginsengprintf"%.3LF%.3LF", Ansx,ansy); - } the intMain () + { Ascanf"%d",&n); the       for(intI=1; i<=n;i++) +scanf"%lf%lf%d",&p[i].x,&p[i].y,&P[I].W); - hillclimb (); $      return 0; $}

Bzoj 3680: amputated xxx "simulated annealing algorithm bare topic learning, mountain climbing algorithm Learning"

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.