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

why???????

Posted by tangr206 at 2009-07-15 16:06:32 on Problem 3253
#include<stdio.h>
#include<stdlib.h>

int cmp(const void*a,const void*b)
{
  return *(int*)b-*(int*)a ;   
}

int main()
{
 int a[20001];
 int i,j,k,n,m;
 __int64 sum=0;
 scanf("%d",&n);    
 for(i=0;i<n;i++)
   scanf("%d",&a[i]);
 
 qsort(a,n,sizeof(int),cmp);      
    
 for(i=0;i<n;i++)
   sum+=a[i];
 sum*=(n-1);
 
 for(i=n;i>1;i--)
  sum-=a[n-i]*(i-2);//重复加的 
  
  printf("%I64d",sum);
  
    
} 

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