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

果然是long long的问题,看来题刷的还不够多啊居然没想到

Posted by 10584004 at 2017-12-05 22:33:10 on Problem 3253
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
    int n,i,j;
    long long sum;

    while(scanf("%d",&n) != EOF){
        long long length[n];
        for(i = 0; i < n; i++){
            scanf("%I64d",&length[i]);
        }
        sort(length,length+n);
        i = 0;
        sum = 0;

        while(i < n-1){
            length[i+1] = length[i] + length[i+1];
            sum += length[i+1];
            for(j = i+1; j < n-1; j++){
                if(length[j] > length[j+1]){
                    swap(length[j],length[j+1]);
                }
            }
            i++;
        }

        printf("%I64d\n",sum);
    }
}
数据再大点估计会超时orz

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