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

这个问题一直比较诡异,经常碰到类似,哪位大牛能解答一下

Posted by hudedi at 2006-05-29 18:18:11 on Problem 2833
In Reply To:哪位高手能帮我看一下,为什么这题我用C++可以AC,用G++就WA? Posted by:tytzyl at 2006-05-28 23:50:10
> #include<stdio.h>
> #include<stdlib.h>
> 
> 
> __int64 s;
> int n,n1,n2,max,min;
> 
> __int64 a[500];
> int solve(__int64);
> int cmp( const void *a, const void *b) 
> { 
>         if(*(int*)a>*(int*)b) 
>                 return 1; 
>         else if(*(int*)a<*(int*)b) 
>                 return -1; 
>         else 
>                 return 0; 
> } 
> 
>  int init(void)
>  {
> 	 __int64 v;
> 	 int i;
> 	scanf("%d%d%d",&n2,&n1,&n);
> 	if(!n1&&!n2&&!n)
> 		return 0;
> 	for(i=0;i<n1+n2;i++)
> 		scanf("%I64d",&a[i]);
> 	qsort((void*)a,n1+n2,sizeof(__int64),cmp);
> 	max=n1-1;min=n1;
> 	s=0;
> 	for(;i<n;i++)
> 	{
> 		scanf("%I64d",&v);
> 		solve(v);
> 	}
> 	return 1;
> 	
>  }
> 
>  int solve(__int64 v)
>  {
> 	 int i;
> 	if(v<a[max])
> 	{
> 		s+=a[max];
> 		a[max]=v;
> 		max=0;
> 		for(i=0;i<n1;i++) if(a[i]>a[max])
> 			max=i;
> 	}
> 	else if(v>a[min])
> 	{
> 		s+=a[min];
> 		a[min]=v;
> 		min=n1;
> 		for(i=n1;i<n1+n2;i++) if(a[i]<a[min])
> 			min=i;
> 	}
> 	else
> 		s+=v;
> 	return 0;
>  
>  }
> 
>  int main()
>  {
> 	long double average;
> 	while(init())
> 	{
> 		average=(long double)s;
> 			average/=(long double)(n-n1-n2);
> 		printf("%.6lf\n",average);
> 	}
> 	return 0;
>  }

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