BZOJ 3680 吊打XXX 计算几何 模拟退火 广义费马点
来源:互联网 发布:韩顺平 php泰牛 编辑:程序博客网 时间:2024/05/22 08:07
题目大意:有个人(gty)被吊打,他机智的使用了分身,但是每个分身有他的重力,把这些gty的分身绑起来,经过一个公共的绳结,求这个绳结最后在哪里。
思路:其实这个题就转化成了:定义一个点到一个分身的距离是两点间的距离 * 分身的重力。求平面内到这些点的距离的和的最小值。和poj2420差不多,这个题只需要在统计的时候吧权值乘上每个分身的重量就可以了。
值得一提的是这个题要求精度到1e-3,写的时候还是有点怕的,但是其实精度把握的合适还是能切这个题的。
一开始MAX开了10000,怎么改参数都是挂。。血的教训啊。。。
CODE:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 10010#define INF 1e17#define EPS 1e-3#define PI acos(-1.0)using namespace std; struct Point{ double x,y; double weight; double total_weight; Point(double _x,double _y):x(_x),y(_y) {} Point() {} void Read() { scanf("%lf%lf%lf",&x,&y,&weight); }}point[MAX],now,ans; int points; inline double Calc(Point p1,Point p2);inline double Statistic(Point p);inline double Rand();void SinulatedAnnealing(); int main(){ srand(19980531); cin >> points; for(int i = 1;i <= points; ++i) { point[i].Read(); now.x += point[i].x; now.y += point[i].y; } now.x /= points,now.y /= points; ans.total_weight = INF; SinulatedAnnealing(); printf("%.3lf %.3lf\n",ans.x,ans.y); return 0;} inline double Calc(Point p1,Point p2){ return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));} inline double Statistic(Point p){ double re = 0.0; for(int i = 1;i <= points; ++i) re += Calc(p,point[i]) * point[i].weight; if(re < ans.total_weight) ans = p,ans.total_weight = re; return re;} void SinulatedAnnealing(){ double T = 100000.0; while(T > EPS) { double alpha = 2.0 * PI * Rand(); Point temp(now.x + T * cos(alpha),now.y + T * sin(alpha)); double dE = Statistic(now) - Statistic(temp); if(dE >= 0 || exp(dE / T) >= Rand()) now = temp; T *= .99; } T = .001; for(int i = 1;i <= 1000; ++i) { double alpha = 2.0 * PI * Rand(); Point temp(ans.x + T * cos(alpha) * Rand(),ans.y + T * sin(alpha) * Rand()); Statistic(temp); }} inline double Rand(){ return (rand() % 1000 + 1) / 1000.0;}
1 0
- BZOJ 3680 吊打XXX 计算几何 模拟退火 广义费马点
- [BZOJ 3680]吊打XXX(广义费马点、模拟退火搜索)
- 【BZOJ3680】吊打XXX 计算几何 广义费马点+模拟退火(爬山算法)
- 【BZOJ3680】吊打XXX 广义费马点 模拟退火
- BZOJ 3680 吊打XXX 模拟退火
- 模拟退火(bzoj 3680: 吊打XXX)
- bzoj 3680 吊打xxx 模拟退火
- [省选前题目整理][BZOJ 3680]吊打XXX(模拟退火)
- 【BZOJ】【P3680】【吊打XXX】【题解】【模拟退火】
- [BZOJ3680]吊打XXX && 模拟退火
- 【bzoj3680】【吊打XXX】【模拟退火】
- BZOJ_P3680 吊打XXX(模拟退火)
- bzoj-3680 吊打XXX
- 【bzoj 3680】吊打XXX
- BZOJ 3680: 吊打XXX
- BZOJ 3680 吊打XXX
- BZOJ3680 吊打XXX(模拟退火算法)
- 【模拟退火\爬山算法】[HYSBZ/BZOJ3680]吊打XXX(吊打GTY)
- hdu 5017 模拟退火算法
- AOP技术应用和研究--动态代理
- jquery选择器之radio 和id
- 进程的通信方式及特点
- Sublime text2 C/C++ 编译环境设置
- BZOJ 3680 吊打XXX 计算几何 模拟退火 广义费马点
- 海纳百川,有容乃大
- C++修改本地组策略
- Android 框架推荐
- hdu 5015 233 Matrix(构造矩阵)
- Ananagrams uva156
- 自己动手写shell之chgrp,chown,chmod
- cocos2d 定时器
- Ural 1961 Cantonese Dialect