#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cstring>
#include<cmath>
#include<algorithm>
#define M 100
using namespace std;
int n,m,a[M],pos[M];
double rev,sum[M],ans,mn=1e30,pre;
void solve()
{
memset(sum,,sizeof(sum));
ans=;
for(int i=;i<=n;i++)
pos[i]=rand()%m+;
for(int i=;i<=n;i++)
sum[pos[i]]+=a[i];
for(int i=;i<=m;i++)
ans+=(sum[i]-rev)*(sum[i]-rev);
double T=;
for(;T>0.1;)
{
int t1=rand()%n+,x=pos[t1],y=rand()%m+;
if(x==y)
continue;
T*=0.9;
pre=ans;
ans-=(sum[x]-rev)*(sum[x]-rev);
ans-=(sum[y]-rev)*(sum[y]-rev);
sum[x]-=a[t1];
sum[y]+=a[t1];
ans+=(sum[x]-rev)*(sum[x]-rev);
ans+=(sum[y]-rev)*(sum[y]-rev);
if(ans>pre)
{
ans=pre;
sum[x]+=a[t1];
sum[y]-=a[t1];
}
else
pos[t1]=y;
}
if(ans<mn)
mn=ans;
return;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
rev+=a[i];
swap(a[i],a[rand()%i+]);
}
rev/=m;
for(int i=;i<=;i++)solve();
printf("%.2lf",sqrt(mn/m));
return ;
}

模拟退火 乱搞

bzoj 2428: [HAOI2006]均分数据的更多相关文章

  1. bzoj 2428: [HAOI2006]均分数据 随机化

    2428: [HAOI2006]均分数据 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...

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

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

  3. BZOJ.2428.[HAOI2006]均分数据(随机化贪心/模拟退火)

    题目链接 模拟退火: 模拟退火!每次随机一个位置加给sum[]最小的组. 参数真特么玄学啊..气的不想调了(其实就是想刷刷最优解) 如果用DP去算好像更准.. //832kb 428ms #inclu ...

  4. 2428: [HAOI2006]均分数据

    模拟退火.一种十分玄学的随机算法,网上可以查到比较详细的资料. 先随机地把数分成m组,每次随机地选择一个数,一开始直接选最小的一组,后来就随机一组,把这个数换到该组看看答案能不能变小,如果变小则换,如 ...

  5. bzoj2428: [HAOI2006]均分数据

    模拟退火.挺好理解的.然后res打成了ans一直WA一直WA...!!!一定要注意嗷嗷嗷一定要注意嗷嗷嗷一定要注意嗷嗷嗷. 然后我就一直卡一直卡...发现最少1800次的时候就可以出解了.然后我就去调 ...

  6. P2503 [HAOI2006]均分数据

    P2503 [HAOI2006]均分数据 模拟退火+dp (不得不说,我今天欧气爆棚) 随机出1个数列,然后跑一遍dp统计 #include<iostream> #include<c ...

  7. bzoj2428 [HAOI2006]均分数据 模拟退火

    [HAOI2006]均分数据 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 3434  Solved: 1091[Submit][Status][Dis ...

  8. 洛谷 P2503 [HAOI2006]均分数据 随机化贪心

    洛谷P2503 [HAOI2006]均分数据(随机化贪心) 现在来看这个题就是水题,但模拟赛时想了1个小时贪心,推了一堆结论,最后发现贪心做 不了, 又想了半个小时dp 发现dp好像也做不了,在随机化 ...

  9. BZOJ 2428 JZYZOJ1533 : [HAOI2006]均分数据 模拟退火 随机化

    http://www.lydsy.com/JudgeOnline/problem.php?id=2428 http://172.20.6.3/Problem_Show.asp?id=1533 http ...

随机推荐

  1. [转载] 多年积累的 mysql 运维经验

    原文: http://mp.weixin.qq.com/s?__biz=MzA3MzYwNjQ3NA==&mid=207132223&idx=1&sn=f5d98146f282 ...

  2. 12 Using_explain_plan

    The row source tree is the core of the execution plan. The tree shows the following information: An ...

  3. php三维数组变二维数组

    <?php $result = Array(0 => Array(0 => Array(bid => 41,brealname => 'we教官',cid => 4 ...

  4. Make 教程

    Make 命令教程 原文作者: 阮一峰 原文链接:http://www.ruanyifeng.com/blog/2015/02/make.html (在原文基础上稍作修改) 代码变成可执行文件,叫做编 ...

  5. 使用Java编写一个简单的Web的监控系统cpu利用率,cpu温度,总内存大小

    原文:http://www.jb51.net/article/75002.htm 这篇文章主要介绍了使用Java编写一个简单的Web的监控系统的例子,并且将重要信息转为XML通过网页前端显示,非常之实 ...

  6. 转 java List 与ArrasyList 区别

    转 List是一个接口,而ListArray是一个类, ListArray继承并实现了List. 为什么要用 List list = new ArrayList() ,而不用 ArrayList al ...

  7. mac10.12的Cocopods安装使用

    Cocopods的安装 CocoaPods应该是iOS最常用最有名的类库管理当我们开发iOS应用时,会经常使用到很多第三方开源类库,比如AFNetWorking等等,可能某个类库又用到其他的库,手动一 ...

  8. nginx日志分析手机使用频次

    __author__ = 'similarface' from collections import defaultdict import glob ip = r"?P<ip>[ ...

  9. LF will be replaced by CRLF in git add

    git add 出现这样的提示: LF will be replaced by CRLF in qinqiu.txt. 这个时候要: $ rm -rf .git  // 删除.git $ git co ...

  10. samtools常用命令详解(转)

    转自:samtools常用命令详解 samtools的说明文档:http://samtools.sourceforge.net/samtools.shtml samtools是一个用于操作sam和ba ...