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

大侠帮忙看看代码,为啥WAWAWA

Posted by symons at 2012-03-12 21:06:10 on Problem 3253
#include<iostream>
using namespace std;
void paixu(int a[],int n)
{
     int i,j,t;
     for(i=0;i<n;i++)
       for(j=i+1;j<n;j++)
        if(a[j]<a[i]) {t=a[j];a[j]=a[i];a[i]=t;}
}
int main()
{
    int a[20010],b[20010];
    int sum,i,j,n,t,sign;
   while( cin>>n){
      sum=0;
      for(i=0;i<n;i++)
      {
       cin>>a[i];
      }
      for(i=0;i<n;i++)
       for(j=i+1;j<n;j++)
        if(a[j]<a[i]) {t=a[j];a[j]=a[i];a[i]=t;}
      
     for(i=0;i<n;i++)
     {
       b[20010]=0;
     }
     n=n-1;
     while(1)
     {
       if(n==0) {break;}
       if(n%2==1)
       {  
         for(i=0;i<=n/2;i++)
         {
           a[i]=a[2*i]+a[2*i+1];
           sum=sum+a[i];//cout<<"sum1="<<sum<<endl;
         }
         n=n/2;
         paixu(a,n);
         //for(i=0;i<n;i++)
        // cout<<a[i]<<" ";
         //cout<<endl;
       }
       else if(n%2==0){
         for(i=0;i<n/2;i++)
         {
           a[i]=a[2*i]+a[2*i+1];
          
           sum=sum+a[i];//cout<<"sum2="<<sum<<endl;
         } a[n/2]=a[n];
         n=n/2;
         paixu(a,n+1);
         //for(i=0;i<n;i++)
        // cout<<a[i]<<" ";
        // cout<<endl;
            }
     }
     cout<<sum<<endl;
  // system("pause");
   }
   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