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 |
cmp返回值分三类,小于返回负数,相等返回0,大于返回正数,*x-*y的值正好符合要求In Reply To:WHY? 又是一次挂在 QSORT 上了 ? 这样为什么会错呢? Posted by:acmpkacm at 2007-01-28 11:30:54 > Problem Id:2291 User Id:acmpkacm > Memory:28K Time:0MS > Language:C++ Result:Wrong Answer > > Source > > #include "stdio.h" > #include "stdlib.h" > long rope[10001]; > > int cmp(const void *a,const void *b) > { > long *x=(long *)a; > long *y=(long *)b; > if(*x>*y) return 1; //这儿改成return(*x-*y) ; 就对了了呢?? 难道这么用错了吗? > return 0; > } > > int main() > { > int t,m,i,j; > long max; > scanf("%d",&t); > while(t--) > { > max=0; > scanf("%d",&m); > for(i=0;i<m;i++) > scanf("%d",&rope[i]); > qsort(rope,m,sizeof(long),cmp); > for(j=m,i=0;j>0;i++,j--) > { > if(max < rope[i] * j ) > max = rope[i] * j; > } > printf("%ld\n",max); > } > return 0; > } > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator