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

为什么我的代码用C++是AC,G++却WA?

Posted by dreamfox at 2009-07-18 21:34:53 on Problem 2833
#include <cstdio>
#include <cstring>
#include <cstdlib>
int maxnum[20];
int minnum[20];
__int64 sum;
int maxn,minn;
int adjust(int root,int len,int check)
{
	int t,j=root<<1;
	bool ck=0;
	if (check==0) t=maxnum[root];
	else t=minnum[root];
	while (j<=len && !ck)
	{
		if (check==0)
		{
			if (j<len && maxnum[j]>maxnum[j+1]) j++;
			if (t<=maxnum[j]) ck=1;
			else
			{
				maxnum[j>>1]=maxnum[j];
				j<<=1;
			}
		}
		else
		{
			if (j<len && minnum[j]<minnum[j+1]) j++;
			if (t>=minnum[j]) ck=1;
			else
			{
				minnum[j>>1]=minnum[j];
				j<<=1;
			}
		}
	}
	if (check==0) maxnum[j>>1]=t;
	else minnum[j>>1]=t;
	return 99;
}
int insert(int root,int pos,int check)
{
	while (check==0 && pos/2>=root && maxnum[pos]<maxnum[pos>>1]) 
	{
		int t=maxnum[pos];
		maxnum[pos]=maxnum[pos>>1];
		maxnum[pos>>1]=t;
		pos>>=1;
	}
	while (check==1 && pos/2>=root && minnum[pos]>minnum[pos>>1])
	{
		int t=maxnum[pos];
		maxnum[pos]=maxnum[pos>>1];
		maxnum[pos>>1]=t;
		pos>>=1;
	}
	return 99;
}
int main()
{
	int n1,n2,n;
	while (scanf("%d%d%d",&n1,&n2,&n),n)
	{
		int i,num;
		sum=0;
		memset(maxnum,0,sizeof(maxnum));
		memset(minnum,0,sizeof(minnum));
		maxn=0;
		minn=0;
		for (i=1;i<=n;i++)
		{
			scanf("%d",&num);
			sum+=num;
			if (maxn<n1)
			{
				maxn++;
				maxnum[maxn]=num;
				insert(1,maxn,0);
			}
			else if (num>maxnum[1])
			{
				maxnum[1]=num;
				adjust(1,maxn,0);
			} 
			if (minn<n2)
			{
				minn++;
				minnum[minn]=num;
				insert(1,minn,1);
			}
			else if (num<minnum[1])
			{
				minnum[1]=num;
				adjust(1,minn,1);
			}
		}
		for (i=1;i<=maxn;i++) sum-=maxnum[i];
		for (i=1;i<=minn;i++) sum-=minnum[i];
		printf("%.6lf\n",double(sum)/(n-maxn-minn));
	}
	return 99;
}

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