Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位高手能帮我看一下,为什么这题我用C++可以AC,用G++就WA?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator