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

wa了n多次,哪位大神帮我看看吧

Posted by haha132 at 2014-03-06 17:31:12 on Problem 2573
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,a[10020];
void init()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    sort(a+1,a+n+1);
}
int slove1(int k)
{
    if(k<3) return a[k];
    if(k==3) return a[1]+a[2]+a[3];
    int minute;
    if(a[k-1]+a[1]<2*a[2]) minute=2*a[1]+a[k]+a[k-1];
    else  minute=2*a[2]+a[1]+a[k];
    minute+=slove1(k-2);
    return minute;
}
void slove2(int k)
{
    if(k==1) {printf("%d\n",a[1]);return ;}
    if(k==2) {printf("%d %d\n",a[1],a[2]);return ;}
    if(k==3) {printf("%d %d\n%d\n%d %d",a[1],a[3],a[1],a[1],a[2]);return ;}
    if(a[k-1]+a[1]<2*a[2]) printf("%d %d\n%d\n%d %d\n,%d\n",a[1],a[k],a[1],a[1],a[k-1],a[1]);
    else   printf("%d %d\n%d\n%d %d\n%d\n",a[1],a[2],a[1],a[k-1],a[k],a[2]);
    slove2(k-2);
}
int main()
{
    init();
    if(n==0) {printf("0\n");return 0;}
    printf("%d\n",slove1(n));
    slove2(n);
    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