首页 技术 正文
技术 2022年11月11日
0 收藏 911 点赞 3,865 浏览 1256 个字

简介

就是模拟退火的物理过程,每次随机逼近乘上温度,以\(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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,495
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,741
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,134
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298