[BZOJ3680]吊打XXX && 模拟退火
2015-04-17 19:38
489 查看
每次随机改变当前中心坐标 然后退火 退火完成后在周围附近在搜索几次(没这个我一直过不了样例)
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<queue> #include<cmath> #define PF printf #define SF scanf using namespace std; typedef long long LL; const int MAXN = 100000; struct Node { double x, y, g; } A[MAXN+10], ans; double Min; int n; inline double dis(const Node &a,const Node &b) { return sqrt((a.x-b.x) * (a.x-b.x) + (a.y-b.y) * (a.y-b.y)); } inline double Rand() { return rand() % 10000 / 10000.0; } double calc(const Node &t) { double ret = 0; for(int i = 1; i <= n; i++) ret += dis(t, A[i]) * A[i].g; if(ret < Min) { Min = ret; ans = t; } return ret; } void SA(double T) { Node Now = ans; while(T > 0.001) { Node New; New.x = Now.x + T * (Rand() * 2 - 1); New.y = Now.y + T * (Rand() * 2 - 1); double dE = calc(Now) - calc(New); if(dE > 0 || exp(dE/T) > Rand()) Now = New; T *= 0.97; } for(int i = 1; i <= 125; i++) calc( (Node) { ans.x + T*(Rand()*2-1), ans.y + T*(Rand()*2-1) } ); } int main() { SF("%d", &n); srand(n+23333); for(int i = 1; i <= n; i++) { SF("%lf%lf%lf", &A[i].x, &A[i].y, &A[i].g); ans.x += A[i].x; ans.y += A[i].y; } ans.x /= n; ans.y /= n; Min = calc(ans); SA(80000); PF("%.3f %.3f", ans.x, ans.y); }
相关文章推荐
- [BZOJ 3680] 吊打XXX 【模拟退火】
- 【bzoj3680】【吊打XXX】【模拟退火】
- 【BZOJ3680】吊打XXX 广义费马点 模拟退火
- [bzoj3680]吊打XXX_模拟退火
- 【BZOJ3680】吊打xxx [模拟退火]
- BZOJ 3680 吊打XXX 计算几何 模拟退火 广义费马点
- 【BZOJ3680】吊打XXX 模拟退火
- 【BZOJ】【P3680】【吊打XXX】【题解】【模拟退火】
- BZOJ3680 & 洛谷1337:[JSOI2004]平衡点/吊打XXX——题解
- [bzoj3680] 吊打XXX:模拟退火 or 模拟力学情景
- BZOJ_3680_吊打XXX_模拟退火
- BZOJ.3680.吊打XXX(模拟退火/爬山算法)
- [BZOJ3680][JSOI2004]平衡点 / 吊打XXX
- BZOJ3680 吊打xxx
- BZOJ 3680: 吊打XXX【模拟退火算法裸题学习,爬山算法学习】
- BZOJ 3680 吊打XXX 模拟退火
- BZOJ 3680 吊打XXX
- 模拟退火法(吊打XXX)Bzoj3680
- bzoj3680: 吊打XXX
- 模拟退火法(吊打XXX)Bzoj3680