您的位置:首页 > 其它

HDU 5073 Galaxy

2015-10-19 19:35 405 查看

Galaxy

Time Limit: 1000ms
Memory Limit: 262144KB
This problem will be judged on HDU. Original ID: 5073
64-bit integer IO format: %I64d Java class name: Main
Special Judge

Good news for us: to release the financial pressure, the government started selling galaxies and we can buy them from now on! The first one who bought a galaxy was Tianming Yun and he gave it to Xin Cheng as a present.

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int maxn = 50010;
LL s[maxn],ss[maxn],a[maxn];
int main(){
int kase,n,k;
scanf("%d",&kase);
while(kase--){
scanf("%d%d",&n,&k);
for(int i = 1; i <= n; ++i)
scanf("%I64d",a + i);
if(n == k){
puts("0");
continue;
}
sort(a + 1,a + n + 1);
for(int i = 1; i <= n; ++i){
s[i] = s[i-1] + a[i];
ss[i] = ss[i-1] + a[i]*a[i];
}
LL ret = 0x3f3f3f3f3f3f3f3f;
for(int i = 0; i <= k; ++i){
LL tmp = (ss[i + n - k] - ss[i])*(n-k);
ret = min(ret,tmp - (s[i + n - k] - s[i])*(s[i + n - k] - s[i]));
}
printf("%.12f\n",ret*1.0/(n-k));
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: