标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4058 | Accepted: 2005 |
Description
Input
Output
Sample Input
4 0 0 0 10000 10000 10000 10000 0
Sample Output
28284
Source
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; #define INF 1e20 #define PI acos(-1.0) #define N 110 struct Point { double x,y; Point(){} Point(double x,double y):x(x),y(y){} }; int n; Point p[N]; double cal(Point t) { double sum=0; for(int i=1;i<=n;i++) sum+=sqrt((p[i].x-t.x)*(p[i].x-t.x)+(p[i].y-t.y)*(p[i].y-t.y)); return sum; } void solve() { int TN=4,DN=100; Point u,v,ansp; double ud,vd,ansd=INF; double step=10000,eps=1e-2,r=0.85; while(TN--) { u=Point(rand()%10000,rand()%10000); ud=cal(u); while(step>eps) { bool flag=1; while(flag) { flag=0; for(int i=0;i<DN;i++) { double d=2*PI*(double)rand()/RAND_MAX; v.x=u.x+sin(d)*step; v.y=u.y+cos(d)*step; vd=cal(v); if(vd<ud) ud=vd,u=v,flag=1; } } step*=r; } if(ud<ansd) ansd=ud,ansp=u; } printf("%.0f\n",ansd); } int main() { //srand((int)time(NULL)); //POJ上不能用 while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); solve(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/hate13/p/4472722.html