Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
快速排序还超时----------------------------------------------------------#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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator