tie的模拟退火版
牛牛战队的比赛地
http://www.nowcoder.com/questionTerminal/ca65cafeb43d4feb8c5d514b27fbdf5d
虽然说只能过50%,后面的tie了
但模拟退火真nb
#include <iostream> #include <cstdio> #include <cmath> #define down 0.996 using namespace std; const int maxn = 1e5 + 5; double xx; double maxdis; int n; struct Point{ double x,y; }p[maxn]; double getmaxdis(double x){ double maxx = 0; for(int i = 0; i < n; i++){ maxx = max(maxx,(p[i].x - x) * (p[i].x - x) + p[i].y * p[i].y); } return maxx; } void sa(){//模拟退火 double t = 3000; while(t > 1e-10){ double ex = xx + (rand() * 2 - RAND_MAX) * t; double edis = getmaxdis(ex); double de = edis - maxdis; if(de < 0){ xx = ex; maxdis = edis; }else if(exp(-de / t) * RAND_MAX > rand()){ xx = ex; } t *= down; } } void solve(){ for(int i = 0; i < 4; i++)sa(); } int main(){ scanf("%d",&n); for(int i = 0; i < n; i++){ scanf("%lf%lf",&p[i].x,&p[i].y); xx += p[i].x; } xx /= n; maxdis = getmaxdis(xx);//初始化 solve(); printf("%.4lf\n",sqrt(maxdis)); return 0; }