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 B06350214 at 2008-01-15 20:48:05 on Problem 3404
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int  main()
{
    int  n;
    int  i;
    int  num[1001];
    while(scanf("%d", &n) != EOF)
    {
        int  ans = 0;
        for(i = 0; i < n; i++)
            scanf("%d", &num[i]);
        sort(num, num+n);
        int f1 = num[0], f2 = num[1];
        int s1 = num[n-1], s2 = num[n-2];
        while(n != 0)
        {
            if(n == 1 || n == 2) {ans += s1; break;}
            if(n == 3) {ans += s2+s1+f1; break;}
            else  if(n >= 4)
            {
                if(2*f2 >= f1+s2){ans += (2*f1+s1+s2);n -= 2; s1 = num[n-1]; s2 = num[n-2];}
                else {ans += (2*f2+f1+s1); n -= 2; s1 = num[n-1]; s2 = num[n-2];}
            }
        }
        printf("%d\n", ans);
    }
    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