| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Why G++ RE,C++ AC#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<utility> #include<cmath> #include<climits> #include<map> #include<time.h> #define debug cout<<"=============debug()==============="<<endl; #define debug_end cout<<"=============debug_end()==========="<<endl; using namespace std; typedef long long ll; const int maxn=5e5+100; const int MAXN=5e4; const int inf=INT_MAX; const double pi=3.14159265358979; int n; double mins=1e100; double res=0; struct point { double x,y; }p[maxn],ans; double dis(point a,point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double check(point a) { res=0; for(int i=1;i<=n;i++) { res+=dis(a,p[i]); } if(res<mins) mins=res,ans=a; return res; } double getrd() { return rand()%10000/10000.0; } void SA(double T) { point now=ans; while(T>0.001) { point newp; newp.x=now.x+T*(getrd()*2-1.0); newp.y=now.y+T*(getrd()*2-1.0); double delta=check(now)-check(newp); if(delta>0||exp(delta/T)>getrd()) now=newp; T*=0.991; } for(int i=1;i<=1000;i++) { point newp; newp.x=ans.x+T*(getrd()*2-1.0); newp.y=ans.y+T*(getrd()*2-1.0); check(newp); } } int main() { srand(time(NULL)); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y),ans.x+=p[i].x,ans.y+=p[i].y; ans.x/=(double)n,ans.y/=(double)n; SA(1000.0); printf("%d",(int)(res+0.5)); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator