#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
//freopen("s.txt","r",stdin);
// freopen("key.txt","w",stdout);
int n,m;
int a[12];
int time=0;
while(cin>>n>>m)
{
int i,j;
double k;
memset(a,0,sizeof(a));
time++;
double sum=0.0;
double temp=0.0;
for(i=0;i<m;i++)
{
cin>>a[i];
sum+=a[i];
}
sum/=n;
sort(a,a+2*n);//????a[0]????a[2n-1]
for(j=0;j<n;j++)
{
k=a[j]+a[2*n-j-1]-sum;
if(k>0)
temp+=k;
else
temp-=k;
}
cout<<"Set #"<<time<<endl;
cout<<"IMBALANCE = "<<fixed<<setprecision(5)<<temp<<endl<<endl;
}
//system("PAUSE");
return 0;
}
1,設(shè)計(jì)到減法注意是否是double類(lèi)型
2,要不要絕對(duì)值,abs(),include<math.h>
3,cout<<fixed<<setprecision(5)能保障小數(shù)點(diǎn)后有(5)幾位小數(shù)
posted on 2009-07-01 10:54
luis 閱讀(208)
評(píng)論(0) 編輯 收藏 引用 所屬分類(lèi):
貪心*二分 、
格式.輸入輸出.數(shù)據(jù)類(lèi)型