BZOJ 2428 [HAOI2006]均分数据 模拟退火
来源:互联网 发布:directx9安装需要网络 编辑:程序博客网 时间:2024/05/29 11:45
题目大意:已知N个正整数:A1、A2、……、An 。今要将它们分成M组,使得各组数据的数值和最平均,即各组的均方差最小。
模拟退火乱搞…
这个参数真的是玄学…
#include <cstdio>#include <cmath>#include <algorithm>#define N 25#define INF 1e20using namespace std;inline int RAND() { return /*(rand()<<15)+*/rand(); }inline double sq(double x) { return x*x; }int n,m,b[N];double a[N],sum[N],ave,ans=INF;double SAA() { //Simulate Anneal Arithmetic for(int i=1;i<=m;++i) sum[i]=0; for(int i=1;i<=n;++i) b[i]=RAND()%m+1, sum[b[i]]+=a[i]; double T=1e5,last,now=0; for(int i=1;i<=m;++i) now+=sq(sum[i]-ave); for(;T>1e-5;T*=0.75) { last=now; int x=RAND()%n+1,y=0; if(T<=1e4) y=rand()%m+1; for(int i=1;i<=m;++i) if(sum[i]<sum[y]) y=i; now+=a[x]*(a[x]+sum[y]-sum[b[x]])*2; if(now>last && T<RAND()%100000) now=last; else sum[b[x]]-=a[x], sum[y]+=a[x], b[x]=y; } return now;}int main() { srand(20000301); scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) scanf("%lf",a+i), ave+=a[i]; sum[0]=INF, ave/=m; for(int i=1;i<=50000;++i) ans=min(ans,SAA()); printf("%.2f\n",sqrt(ans/m)); return 0;}
阅读全文
0 0
- bzoj:2428: [HAOI2006]均分数据 模拟退火
- BZOJ 2428 [HAOI2006]均分数据 模拟退火
- BZOJ 2428: [HAOI2006]均分数据 模拟退火
- bzoj 2428: [HAOI2006]均分数据 (模拟退火)
- [BZOJ2428] [HAOI2006]均分数据 && 模拟退火
- BZOJ2428: [HAOI2006]均分数据 模拟退火
- [BZOJ2428][HAOI2006]均分数据(模拟退火)
- bzoj2428 [HAOI2006]均分数据 模拟退火
- [HAOI2006]均分数据(模拟退火????)
- bzoj 2428 均分数据 模拟退火
- bzoj 2428 [HAOI2006]均分数据
- bzoj 2428: [HAOI2006]均分数据
- BZOJ 2428: [HAOI2006]均分数据
- BZOJ2428 [HAOI2006]均分数据(模拟退火算法)
- 模拟退火——BZOJ2428/Luogu2503 [HAOI2006]均分数据
- [BZOJ 2428][HAOI 2006]均分数据(模拟退火)
- 2428: [HAOI2006]均分数据
- 【HAOI2006】【BZOJ2428】均分数据
- codeforces 812b Sagheer, the Hausmeister
- Linux系统内存管理
- 【脚本语言系列】关于PythonWeb服务器Bottle,你需要知道的事
- grep、sed、awk命令使用参数说明
- CSS3线性渐变与径向渐变
- BZOJ 2428 [HAOI2006]均分数据 模拟退火
- bash脚本基础(二)
- Flask成长笔记--依赖包操作
- Leetcode 332 Reconstruct Itinerary
- vlc for android 完全编译
- dup/dup2/dup3(输入文件描述符重定向)
- 【脚本语言系列】关于PythonWeb服务器Flask,你需要知道的事
- 60. Permutation Sequence
- mysql-5.7.18-winx64 免安装版服务无法启动的解决