http://www.lydsy.com/JudgeOnline/problem.php?id=2428
http://172.20.6.3/Problem_Show.asp?id=1533
http://blog.****.net/qpswwww/article/details/44161053
本来用了看的博客里的srand想缩短时间不知道为什么wa了,在本校oj也挂了一组,但是不管是挂的数据在本地测,还是成组数据在本地测都是ac的。问了学长然后去掉了srand提高了次数,ac了。应该就是srand的锅,因为在bzoj上不去掉srand提高次数也是wa。
/**************************************************************
Problem: 2428
User: 137shoebills
Language: C++
Result: Accepted
Time:4884 ms
Memory:1304 kb
****************************************************************/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=;
int n,m;
int a[maxn]={};
int org[maxn]={};
int sum[maxn]={};
double xa=,ans=;
void doit(){
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++){
org[i]=rand()%m+;
sum[org[i]]+=a[i];
}
double cnt=,lcnt,T=;
for(int j=;j<=m;j++){
cnt+=((double)sum[j]-xa)*((double)sum[j]-xa);
}cnt/=(double)m;
while(T>0.1){//温度设定
T*=0.9;
int x=rand()%n+,y,mi=;//随机选一个数,最小和对应位置,最小和
if(T>)//温度高贪心温度低随机
for(int i=;i<=m;i++){if(mi>sum[i]){mi=sum[i];y=i;}}
else y=rand()%m+;
if(y==org[x]){continue;} sum[org[x]]-=a[x];sum[y]+=a[x];
lcnt=cnt;cnt=;//重新算方差
for(int j=;j<=m;j++){
cnt+=((double)sum[j]-xa)*((double)sum[j]-xa);
}cnt/=(double)m; if(cnt<lcnt)org[x]=y;
else if(rand()%>T)org[x]=y,cnt=lcnt;
else{
sum[org[x]]+=a[x];sum[y]-=a[x];
}
if(cnt<ans)ans=cnt;//更新答案
}
}
int main(){
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
scanf("%d%d",&n,&m);
//srand(20010123);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);xa+=a[i];
}xa/=(double)m;
for(int i=;i<=;i++)doit();
printf("%.2f\n",sqrt(ans));
return ;
}