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 a296891673 at 2012-04-20 21:22:29 on Problem 1700
#include<stdio.h>
#include<stdlib.h>
 int main()
     {
          long i, j, k, m, n, r, s, t, sum;
          int ai[100];
          
          scanf("%d%d", &m, &n);
          
          while(m--)
              {
                  for(i=0; i<n; i++)
                      scanf("%d", &ai[i]);
                  for(i=1; i<n; i++)
                      for(j=0; j<n-i; j++)
                          if( ai[j]>ai[j+1] )
                              {
                                 k=ai[j];
                                 ai[j]=ai[j+1];
                                 ai[j+1]=k;              
                              }      
                  
                  sum=0;
                  r=n-1;
                  s=ai[0];
                  t=ai[1];
                  while(r>2)
                      {
                           if((s+t+ai[r]+t)<(ai[r]+ai[r-1]+s+s) )
                               sum+=(s+t+ai[r]+t);                                                   
                           else
                               sum+=(ai[r]+ai[r-1]+s+s);
                           r-=2;                                                          
                      }
                  if(r==1)
                      sum+=t;
                  else
                  if(r==0)
                      sum+=s;
                  else
                  if(r==2)
                      sum+=(t+s+ai[r]); 
                  r=sizeof(sum);
                  printf("%d\n", r);
                  printf("%d\n", sum);
              }
        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