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

Re:是不是qsort(cow,num,sizeof(long),comp);错了,把long改__int64试试

Posted by ray58750034 at 2005-03-05 23:46:57 on Problem 2231
In Reply To:那位帮看一下吧 到底哪里错了 wa了n次了 Posted by:waternet at 2005-03-05 23:28:24
> #include <stdio.h>
> #include <math.h>
> int comp(void* a,void *b){
>     long *p=(long*)a;
>     long *q=(long*)b;
>     return *p>*q;
> }    
> int main(){
>     long cow[10000],num,i,j;
>     __int64 noise=(__int64)0;
>     scanf("%d",&num);   
>     for(i=0;i<num;i++){
>         scanf("%d",&cow[i]);
>     }
>     qsort(cow,num,sizeof(long),comp);
>     for(i=1;i<num;i++){
>         noise=noise+(__int64)2*i*(num-i)*(cow[i]-cow[i-1]);
>     }    
>     printf("%I64d\n",noise);
>     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