洛谷P1337 [JSOI2004]平衡点 / 吊打XXX
作者:互联网
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef double db; 5 const int N=1e3+5; 6 db ansx,ansy,answ; 7 int n; 8 struct point{ 9 int x,y,w; 10 }p[N]; 11 12 ll read() 13 { 14 ll x=0,f=1;char ch=getchar(); 15 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 16 while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} 17 return x*f; 18 } 19 db f(db x,db y) 20 { 21 db sum=0; 22 for(int i=1;i<=n;i++) 23 { 24 db delx=x-p[i].x; 25 db dely=y-p[i].y; 26 sum+=1.0*sqrt(delx*delx+dely*dely)*p[i].w; 27 } 28 return sum; 29 } 30 void mnth() 31 { 32 for(db T=3000;T>1e-15;T*=0.996) 33 { 34 db nowx=ansx+(2*rand()-RAND_MAX)*T; 35 db nowy=ansy+(2*rand()-RAND_MAX)*T; 36 db delt=f(nowx,nowy)-f(ansx,ansy); 37 if(delt<0)ansx=nowx,ansy=nowy; 38 else if(exp(-delt/T)*RAND_MAX>rand())ansx=nowx,ansy=nowy; 39 } 40 } 41 int main() 42 { 43 n=read(); 44 for(int i=1;i<=n;i++) 45 { 46 p[i].x=read();p[i].y=read();p[i].w=read(); 47 ansx+=p[i].x;ansy+=p[i].y; 48 } 49 ansx/=n;ansy/=n; 50 mnth(); 51 mnth(); 52 printf("%.3lf %.3lf\n",ansx,ansy); 53 return 0; 54 }
标签:ansx,ansy,ch,洛谷,JSOI2004,int,ll,db,吊打 来源: https://www.cnblogs.com/matt-su/p/16096170.html