简介

就是模拟退火的物理过程,每次随机逼近乘上温度,以\(e^{\Delta/T}\)的概率接受答案,随机一个概率比较

然后就是调参+乱搞

题目

Bzoj3680:吊打xxx

代码

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1005); IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} const double EPS(1e-15);
const double dt(0.99); double x[_], y[_], w[_], ans, ansx, ansy;
int n; # define Sqr(x) ((x) * (x))
IL double Dis(RG double x1, RG double y1, RG double x2, RG double y2){
return sqrt(Sqr(x1 - x2) + Sqr(y1 - y2));
} IL double Sum(RG double x0, RG double y0){
RG double ret = 0;
for(RG int i = 1; i <= n; ++i) ret += Dis(x[i], y[i], x0, y0) * w[i];
return ret;
} IL double SA(RG double T){
RG double x0 = ansx, y0 = ansy, cnt = 1e18;
for(; T > EPS; T *= dt){
RG double dx = rand() * 2 - RAND_MAX, dy = rand() * 2 - RAND_MAX;
RG double xx = x0 + T * dx;
RG double yy = y0 + T * dy;
RG double ret = Sum(xx, yy);
if(ret < ans) ans = ret, ansx = xx, ansy = yy;
if(ret < cnt || exp((cnt - ret) / T) * RAND_MAX > rand()){
cnt = ret;
x0 = xx, y0 = yy;
}
}
} int main(RG int argc, RG char* argv[]){
n = Input();
srand(n + 19260817); RG double x0 = 0, y0 = 0;
for(RG int i = 1; i <= n; ++i) x[i] = Input(), y[i] = Input(), w[i] = Input();
for(RG int i = 1; i <= n; ++i) x0 += x[i], y0 += y[i];
x0 /= n; y0 /= n; ansx = x0; ansy = y0;
ans = Sum(x0, y0);
SA(100000);
printf("%.3lf %.3lf\n", ansx, ansy);
return 0;
}

最新文章

  1. 好像越来越觉得 SharePoint &ldquo;难用&rdquo;了
  2. Python数据结构与算法设计总结篇
  3. HQL查询——select子句
  4. web前端基础篇⑩
  5. 【管理心得之三十】&quot;这事与我无关&quot;
  6. ZJOI 游记
  7. (转)SQL SERVER的锁机制(四)——概述(各种事务隔离级别发生的影响)
  8. Mysql索引总结(一)
  9. Java 多字段排序Comparator(兼容Date,Integer,Doubel,Long)
  10. gsoap入门实例
  11. java--Object类接受任意引用数据类型对象
  12. Sprk SQL
  13. mysql学习二、SQL常用数据类型
  14. python中建模分析零息票收益率曲线--复利和连续复利
  15. JS实现倒计时(天数,时,分,秒)
  16. Jmeter --- 组件执行顺序与作用域
  17. 《jQuery基础教程(第四版)》学习笔记
  18. [转帖]PG里面的Citus简介----找时间学习一下.
  19. IPC_Binder_java_2
  20. Could not connect to &#39;192.168.80.145&#39; (port 22): Connection failed的解决办法(远程连不上xshell)

热门文章

  1. 【JavaWeb】权限管理系统
  2. J2ee的13个规范
  3. 简单模拟一下ab压力测试
  4. 买帽子 (hash)
  5. SIFT解析(一)建立高斯金字塔
  6. day6(列表操作、列表练习题)
  7. 转:客户端session与服务端session
  8. 关于longPressGesture做一个长按连加的效果(原创)
  9. 用Node.JS+MongoDB搭建个人博客(页面模板)(五)(结束)
  10. 自动化测试(—)Web自动化测试理解