posts - 195,  comments - 30,  trackbacks - 0
#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,设计到减法注意是否是double类型
2,要不要绝对值,abs(),include<math.h>
3,cout<<fixed<<setprecision(5)能保障小数点后有(5)几位小数
posted on 2009-07-01 10:54 luis 阅读(180) 评论(0)  编辑 收藏 引用 所属分类: 贪心*二分格式.输入输出.数据类型

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年7月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

友情链接

搜索

  •  

最新评论

阅读排行榜

评论排行榜