//yy:今天简单入门学了下ORZ

爬山算法:兔子朝着比现在高的地方跳去。它找到了不远处的最高山峰。但是这座山不一定是珠穆朗玛峰。这就是爬山算法,它不能保证局部最优值就是全局最优值。

模拟退火:兔子喝醉了。它随机地跳了很长时间。这期间,它可能走向高处,也可能踏入平地。但是,它渐渐清醒了并朝最高方向跳去。这就是模拟退火。

题目链接:BZOJ 3680: 吊打XXX

1<=n<=10000,-100000<=xi,yi<=100000

题意:找一个点,使得最小

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#define FIRE(x) (x *= 0.98)
using namespace std;
typedef long long ll;
const int N = ;
const double inf = 1e17;
const double PI = acos(-1.0);
const double eps = 1e-;
struct Point{
double x, y, w;
Point(){}
Point(double _x, double _y):x(_x), y(_y) {}
Point operator -(const Point &b)const{
return Point(x - b.x,y - b.y);
}
double operator *(const Point &b)const{
return x*b.x + y*b.y;
}
}now, ans, po[N];
double dist(Point a, Point b) {return sqrt((a-b)*(a-b));}
int n;
double tot = inf;
double statistic(Point p) {
double res = 0.0;
for(int i = ; i < n; ++i) res += dist(p, po[i]) * po[i].w;
if(res < tot) tot = res, ans = p;
return res;
}
double Rand() {return (rand()% + ) / 1000.0;}
void SA(double T) {
double alpha, sub;
while(T > eps) {
alpha = 2.0 * PI * Rand();
Point t(now.x + T * cos(alpha), now.y + T * sin(alpha));
sub = statistic(now) - statistic(t);
if(sub >= || exp(sub / T) >= Rand()) now = t;
FIRE(T);
}
T = 0.001;
for(int i = ; i <= ; ++i) {
alpha = 2.0 * PI * Rand();
Point t(ans.x + T * cos(alpha) * Rand(), ans.y + T * sin(alpha) * Rand());
statistic(t);
}
}
int main(){
srand();
scanf("%d", &n);
for(int i = ; i < n; ++i) {
scanf("%lf%lf%lf", &po[i].x, &po[i].y, &po[i].w);
now.x += po[i].x; now.y += po[i].y;
}
now.x /= n; now.y /= n;
double T = 1000.0;
SA(T);
printf("%.3f %.3f\n", ans.x, ans.y);
return ;
}

BZOJ 3680: 吊打XXX (模拟退火)的更多相关文章

  1. bzoj 2428: [HAOI2006]均分数据 && bzoj 3680 : 吊打XXX 模拟退火

    每次把元素随便扔随机一个初始解,退火时每次随机拿一个元素扔到随机一个集合里,当温度高时因为状态不稳定扔到那个元素和最小的里边. 如果新解优,更新ans. 把原式拆一下,就可以用int存了. bzoj ...

  2. 洛谷 P1337 平衡点 & bzoj 3680 吊打 XXX —— 模拟退火

    题目:https://www.luogu.org/problemnew/show/P1337 https://www.lydsy.com/JudgeOnline/problem.php?id=3680 ...

  3. bzoj 3680 吊打xxx 模拟退火

    第一道模拟退火 重心嘛,就是要找到一个点,使其到所有点距离*该点权值和最小 思路:初始化一个T,mint,当T大于mint时,每次随机一个解,如果解比当前解优,直接转移,否则,以某概率(与T正相关)转 ...

  4. BZOJ.3680.吊打XXX(模拟退火/爬山算法)

    题目链接 一个比较好的解释? 模拟退火(Simulated Annealing,SA): (1)初始化一个温度(充分大).初始解状态S.每个T值的迭代次数. (2)对i=1,...,L,做(3)至(7 ...

  5. BZOJ 3680: 吊打XXX【模拟退火算法裸题学习,爬山算法学习】

    3680: 吊打XXX Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 3192  Solved: 1198[Sub ...

  6. [BZOJ 3680] 吊打XXX 【模拟退火】

    题目链接:BZOJ - 3680 题目分析 这道题是SLYZ的神犇把JSOI的平衡点那道题改了一下题面变成了吊打GTY神犇..Orz 第一次写模拟退火,只能照着别人的代码写,我看的是PoPoQQQ神犇 ...

  7. BZOJ 3680 吊打XXX

    Description gty又虐了一场比赛,被虐的蒟蒻们决定吊打gty.gty见大势不好机智的分出了n个分身,但还是被人多势众的蒟蒻抓住了.蒟蒻们将n个gty吊在n根绳子上,每根绳子穿过天台的一个洞 ...

  8. 3680: 吊打XXX

    3680: 吊打XXX 链接 思路: 模拟退火. 代码: 跑的特别慢... #include<cstdio> #include<algorithm> #include<c ...

  9. 【BZOJ3680】吊打xxx [模拟退火]

    吊打XXX Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description gty又虐了一场比赛,被虐的蒟蒻 ...

随机推荐

  1. C#(Winform)禁用TextBox控件的鼠标事件

    1. 继承TextBox,然后重写父类的部分方法,核心代码如下 public class MyTextBox : TextBox { protected override void WndProc(r ...

  2. Redis云端架构深入浅出

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯云数据库 TencentDB 发表于云+社区专栏 作者介绍:邹鹏,腾讯云数据库Redis产品负责人,多年数据库.网络安全研发经验. ...

  3. 【c++】iostreeam中的类为何不可以直接定义一个无参对象呢

    缘起 #include <iostream> #include <fstream> #include <sstream> using namespace std; ...

  4. 从websphere6.1迁移到weblogic10.3的问题总结--转

    http://blog.itpub.net/9399028/viewspace-692974/ 以前用weblogic低版本的时候,感觉挺容易的,也没什么要注意的,这次真正把应用从websphere迁 ...

  5. codeforces 675 C ——Money Transfers——————【思维题】

    Money Transfers time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. bzoj 3064: Tyvj 1518 CPU监控

    Description 1.区间加 \(z\) 2.区间覆盖为 \(z\) 3.查询区间最大值 4.查询区间历史最大值 Solution 线段树维护历史最值,思想大致是维护标记出现过的最大值 考虑这种 ...

  7. 原创经验:微信小程序开发总结

    学习时间不短了.今天公司不加班总结一下我的开发经验吧,以下都是我认为很重要的总结哦!写下来让我自己也记得更清楚,同时希望可以帮助到有需要的同学哦 一: 参数传值的方法 1:  data-id我们可以给 ...

  8. WPF binding<一> Data Binding在WPF中的地位

    在代码中看到 <Image Source="{Binding ElementName=LBoxImages, Path=SelectedItem.Source}" /> ...

  9. easyui表单校验拓展

    /** * Created by chaozhou on 2016/5/30. */ /** * 扩展的基本校验规则, */ $.extend($.fn.validatebox.defaults.ru ...

  10. tomcat启动编码等部署遇到问题

    版权声明:本文为博主原创文章,转载请注明文章链接.https://blog.csdn.net/xiaoanzi123/article/details/58254318 2017-02-27 21:01 ...