BZOJ3680 JSOI2004 Equilibrium Point-stochastic/approximate algorithm

Source: Internet
Author: User
Tags abs

The iteration was messed up and it was over ...

#include <bits/stdc++.h>using namespacestd;Doublex[10005],y[10005],w[10005];DoubleXm,ym,wt,k,lambda=0.9;intN;Const Doubleox[5]={0,1,0,-1,0},oy[5]={0,0,1,0,-1};DoubleCalcDoubleXwDoubleyw) {    Doubleans=0;  for(intI=1; i<=n;i++) ans+=sqrt ((Xw-x[i]) * (Xw-x[i]) + (Yw-y[i]) * (yw-y[i)) *W[i]; returnans;}intMain () {CIN>>N;  for(intI=1; i<=n;i++) Cin>>x[i]>>y[i]>>W[i], XM+=x[i]*w[i], ym+=y[i]*W[i], K=Max (K,max (ABS (X[i), ABS (Y[i))), WT+=W[i]; XM/=wt; Ym/=wt; K*=0.1; Doublez=0, oz=-1e+8;  while(k>=0.0001) {        //printf ("%.3f%.3f k=%.4f\n", xm,ym,k);oz=Z; DoubleMinopt=1e+ -; intopt=0;Doubletmp;  for(intI=0; i<=4; i++) {tmp=calc (xm+ox[i]*k,ym+oy[i]*k); if(tmp<minopt) minopt=tmp, opt=i; } XM+=ox[opt]*k, ym+=oy[opt]*K; Z=tmp; K*=Lambda; } printf ("%.3f%.3f\n", Xm,ym); }

BZOJ3680 JSOI2004 Equilibrium Point-stochastic/approximate algorithm

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.