Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高手看看为什么WA,附注释

Posted by windows8 at 2009-11-14 22:31:21 on Problem 2833
#include<stdio.h>
#include<algorithm>
using namespace std;
int s[500011],a,b,l[11],g[11],MAX=999999999;
double sum;
int cmp(const void *a,const void *b)
{return *(int*)a-*(int*)b;}
void f(int m)
{int i,j;
for(i=0;i<m;i++)
	{scanf("%d",&s[i]);
	sum+=s[i];//求总和
	}
for(j=0;j<a;j++)//将最小值附加到排序数组
	s[i++]=l[j];
qsort(s,m+a,sizeof(s[0]),cmp);//排序
for(i=0;i<a;i++)//更新最小值
	l[i]=s[i];
for(i=0;i<b;i++)
	for(j=0;j<b;j++)
		if(g[i]<s[m+a-j-1]&&s[m+a-j-1]!=MAX)//更新最大值
			{g[i]=s[m+a-j-1];
			s[m+a-j-1]=0;}
}
int main()
{int n,i;
while(scanf("%d%d%d",&b,&a,&n),a+b+n)//b最大值个数,a最小值个数
{sum=0;
//if(n>=500000)
if(n>=100)//分组处理
	{for(i=0;i<a;i++)//最小值初始化
		l[i]=MAX;
	for(i=0;i<b;i++)//最大值初始化
		g[i]=0;
	int start=0;
	for(i=0;i<9;i++)//处理前9组
		f(n/10),start+=n/10;
	f(n-start);//处理最后一组
	for(i=0;i<a;i++)//减去最小值
		sum-=l[i];
	for(i=0;i<b;i++)//减去最大值
		sum-=g[i];
//printf("%f\n",sum);
	}
else//小数组
	{for(i=0;i<n;i++)
		scanf("%d",&s[i]);
	qsort(s,n,sizeof(s[0]),cmp);
	for(i=a;i<n-b;i++)
		sum+=s[i];
	}
printf("%f\n",sum/(n-a-b));
}
}



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator