bzoj3680: 吊打XXX
2018-05-06 14:42
330 查看
题目链接
bzoj3680: 吊打XXX题解
物理题问题转化为求力的重心
模拟退火即可
代码
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> const int maxn = 100007; double x[maxn],y[maxn],w[maxn]; int n;double ansx,ansy,nowx,nowy,Ans = 1.0 * 1e18; double calc(double X,double Y) { double ret = 0; for(int i = 1;i <= n;++ i) ret += w[i] * sqrt((X - x[i]) * (X - x[i]) + (Y - y[i]) * (Y - y[i])); if(ret < Ans) Ans = ret,ansx = X,ansy = Y; return ret; } double Random() {return (double) rand() / RAND_MAX;} void SA(double T) { nowx = ansx,nowy = ansy; double tmpx ,tmpy; while(T > 0.001) { tmpx = nowx + T * (Random() * 2 - 1); tmpy = nowy + T * (Random() * 2 - 1); double DE = calc(nowx,nowy) - calc(tmpx,tmpy); if(DE > 0 || Random() <= exp(DE/T)) nowx = tmpx,nowy = tmpy; T *= 0.98; } for(int i = 1;i <= 1000;++ i) { tmpx = ansx + T * (Random() * 2 - 1) ; tmpy = ansy + T * (Random() * 2 - 1) ; calc(tmpx,tmpy); } } int main() { srand(19260817); scanf("%d",&n); for(int i = 1;i <= n;++ i) scanf("%lf%lf%lf",x + i,y + i,w + i), ansx += x[i],ansy += y[i]; ansx /= n;ansy /= n; //printf("%lf %lf\n",Ans,ansy); SA(40000001); printf("%.3lf %.3lf",ansx,ansy); return 0; }
相关文章推荐
- 模拟退火法(吊打XXX)Bzoj3680
- BZOJ.3680.吊打XXX(模拟退火/爬山算法)
- BZOJ3680 : 吊打XXX
- BZOJ 3680 吊打XXX
- 模拟退火法(吊打XXX)Bzoj3680
- BZOJ 3680 吊打XXX 爬山算法
- [bzoj3680] 吊打XXX:模拟退火 or 模拟力学情景
- 【BZOJ3680】吊打XXX
- [bzoj3680]吊打XXX_模拟退火
- 【BZOJ3680】吊打XXX 计算几何 广义费马点+模拟退火(爬山算法)
- 【BZOJ3680】吊打xxx [模拟退火]
- BZOJ3680 吊打XXX
- bzoj3680 吊打XXX
- bzoj3680: 吊打XXX
- BZOJ3680 吊打xxx
- 【bzoj 3680】吊打XXX
- bzoj3680: 吊打XXX
- 【BZOJ3680】吊打XXX 模拟退火
- [JSOI2004]平衡点/[BZOJ3680]吊打XXX
- bzoj-3680 吊打XXX