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

郁闷,为什么不能过?TLE

Posted by shenfangyi at 2006-08-06 21:55:08 on Problem 2299
#include<stdio.h>
long long a[500000];
long long aa;
void gb(int x,int y)
{
    if(x<y)
    {
           gb(x,(x+y)/2);
           gb((x+y)/2+1,y);
           int i=x,j=(x+y)/2+1,k,s;
           while((i<j)&&(j<=y))
           {
                               while((a[i]<=a[j])&&(i<j))i++;
                               aa+=j-i;
                               s=a[j];
                               for(k=j;k>i;k--)a[k]=a[k-1];
                               a[i]=s;
                               i++;
                               j++;
           }
    }
}
main()
{
    int n;
    scanf("%d",&n);
    while(n)
    {
        for(int i=0;i<n;i++)scanf("%I64d",a+i);
        aa=0;
        gb(0,n-1);
        printf("%I64d\n",aa);
        scanf("%d",&n);
    }
}

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