Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 快速排序还超时----------------------------------------------------------

Posted by jianxiao at 2008-07-21 10:58:13 on Problem 1423
```#include <stdio.h>
#include <math.h>
struct ci
{
int a;
int sort;
}num[50];
void quickSort(int startPos, int endPos)
{
int i,j;
ci ch;
ch=num[startPos];
i=startPos;
j=endPos;
while(i<j)
{
while(num[j].a>=ch.a && i<j)--j;
num[i]=num[j];
while(num[i].a<=ch.a && i<j)++i;
num[j]=num[i];
}
num[i]=ch;
if(i-1>startPos) quickSort(startPos,i-1);
if(endPos>i+1) quickSort(i+1,endPos);
}

int main()
{
int n,i,j,log[50],c[50];
double no,d;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d",&num[i].a);
num[i].sort=i;
}
quickSort(0,n-1);

d=0.0;
for(i=1;i<num[0].a;i++)
d=d+log10(i);
log[num[0].sort]=(int )d+2;
for(i=1;i<n;i++)
{
for(j=num[i-1].a;j<num[i].a;j++)
d=d+log10(j);
log[num[i].sort]=(int)d+2;
}
for(i=0;i<n;i++)
printf("%d\n",log[i]);
}
return 0;
}
```

Followed by: