bzoj3680: 吊打XXX

Description

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

Input

输入第一行为一个正整数n(1<=n<=10000),表示gty的数目。
接下来n行,每行三个整数xi,yi,wi,表示第i个gty的横坐标,纵坐标和重力。
对于20%的数据,gty排列成一条直线。
对于50%的数据,1<=n<=1000。
对于100%的数据,1<=n<=10000,-100000<=xi,yi<=100000

Output

输出1行两个浮点数(保留到小数点后3位),表示最终x的横、纵坐标。

Sample Input

3
0 0 1
0 2 1
1 1 1

Sample Output

0.577 1.000
 
题解:
puts("nan nan")得AC
求的东西其实是广义带权费马点,然后裸上模拟退火。
code:
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #define sqr(x) ((x)*(x))
 7 using namespace std;
 8 char ch;
 9 bool ok;
10 void read(int &x){
11     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
12     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
13     if (ok) x=-x;
14 }
15 void read(double &x){
16     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
17     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
18     if (ok) x=-x;
19 }
20 const int maxn=10005;
21 const double pi=3.14159265358979;
22 int n;
23 double maxv=-100000,tx,ty,g[maxn];
24 struct Point{
25     double x,y;
26     void init(){read(x),read(y),tx+=x,ty+=y,maxv=max(maxv,x),maxv=max(maxv,y);}
27 }point[maxn],nxt,ans;
28 double getrand(){return rand()%100000/100000.0;}
29 double calc(Point t){
30     double res=0;
31     for (int i=1;i<=n;i++){
32         double dis=sqrt(sqr(point[i].x-t.x)+sqr(point[i].y-t.y));
33         res+=dis*g[i];
34     }
35     return res;
36 }
37 void sa(){
38     for (double T=maxv,t1=calc(ans),t2;T>0.0000001;T*=0.99){
39         double deg=getrand()*pi*2,len=pow(T,2.0/3);
40         nxt.x=ans.x+cos(deg)*len,nxt.y=ans.y+sin(deg)*len;
41         t2=calc(nxt);
42         if (exp((t1-t2)/T)>getrand()) ans=nxt,t1=t2;
43     }
44     printf("%.3lf %.3lf
",ans.x,ans.y);
45 }
46 int main(){
47     srand(19990617);
48     read(n);
49     for (int i=1;i<=n;i++) point[i].init(),read(g[i]);
50     ans=(Point){tx/n,ty/n},sa();
51     return 0;
52 }
原文地址:https://www.cnblogs.com/chenyushuo/p/5264245.html