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 jackstraw at 2006-12-28 16:20:37 on Problem 2231
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

long l[100000];
long left[1000000];


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


int main() {
    //freopen("pku2231.in", "r", stdin);
    //freopen("pku2231.out", "w+", stdout);
    int n;
    __int64 result;
    while (scanf("%d", &n) == 1) {
        result = 0;
        for (int i = 1; i <= n; i++) {
            scanf("%ld", &l[i]);
        }
        if (n == 0) {
            printf("0\n");
            continue;
        }
        qsort(&l[1], n, sizeof(long), compare);
        left[1] = 0;
        
        for (int i = 2; i <= n; i++) {
            left[i] = left[i - 1] + (i - 1) * (l[i] - l[i - 1]);
            result += left[i];
        }
        
        printf("%I64d\n", 2 * result);
    }
    
    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