# BZOJ 3680: 吊打XXX

## 3680: 吊打XXX

Time Limit:10 Sec  Memory Limit:128 MBSec  Special Judge
Submit: 2743  Solved: 1006
[Submit][Status][Discuss]

## Description

gty又虐了一场比赛，被虐的蒟蒻们决定吊打gty。gty见大势不好机智的分出了n个分身，但还是被人多势众的蒟蒻抓住了。蒟蒻们将n个gty吊在n根绳子上，每根绳子穿过天台的一个洞。这n根绳子有一个公共的绳结x。吊好gty后蒟蒻们发现由于每个gty重力不同，绳结x在移动。蒟蒻wangxz脑洞大开的决定计算出x最后停留处的坐标，由于他太弱了决定向你求助。

3
0 0 1
0 2 1
1 1 1

## Sample Output

0.577 1.000

#include<cmath>
#include<ctime>
#include<cstdio>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<set>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return f*x;
}
const int N=10010;const double eps=1e-5;
int n;
double ansx,ansy,x[N],y[N],w[N],ans;
inline double sqr(double x){return x*x;}
inline double dis(double x,double y,double bx,double by){return sqrt(sqr(x-bx)+sqr(y-by));}
inline double cal(double tx,double ty)
{
double temp=0.0;
for(int i=1;i<=n;i++)temp+=w[i]*(dis(x[i],y[i],tx,ty));
if(temp<ans)ans=temp,ansx=tx,ansy=ty;return temp;
}
inline double getrand()
{return (double)(rand()%20000)/20000;}
int main()
{
n=read();
for(int i=1;i<=n;i++)scanf("%lf%lf%lf",&x[i],&y[i],&w[i]);
for(int i=1;i<=n;i++)ansx+=x[i],ansy+=y[i];
ansx/=n;ansy/=n;ans=cal(ansx,ansy);
double tx,ty;double t=1e5;
srand(time(NULL));
while(t>eps)
{
tx=ansx+t*(getrand()*2-1); ty=ansy+t*(getrand()*2-1);
cal(tx,ty);t*=0.97;
}
printf("%.3lf %.3lf\n",ansx,ansy);
return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define eps 1e-6
double x[10005],y[10005],w[10005];
double dis(double x1,double y1,double x2,double y2)
{
double d=sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
if(d>-eps&&d<eps) return eps;
return d;
}
int main()
{
double t,xx=0.0,yy=0.0,fx,fy,F;//设初始位置为(0,0)
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%lf%lf%lf",&x[i],&y[i],&w[i]);
for(t=10000;t>0.00001;t*=0.99)//t:步长
{
fx=fy=0;
for(i=1;i<=n;i++)
{
fx+=w[i]*(x[i]-xx)/dis(x[i],y[i],xx,yy);//fx:水平合外力
fy+=w[i]*(y[i]-yy)/dis(x[i],y[i],xx,yy);//fy:竖直合外力
}
F=dis(fx,fy,0,0);//F:合外力，(fx/F,fy/F)为合外力的方向向量
if(F<0.0001)break;
xx+=t*fx/F;
yy+=t*fy/F;
}
printf("%.3lf %.3lf",xx,yy);
return 0;
}