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 |
膜拜一下先In Reply To:用汇编写的程序,居然都才61MS。。。 Posted by:zyl072 at 2007-08-10 19:22:04 > 从快速排序到二分查找,全是用汇编写的,居然都用了61MS,不知道前面的大牛是怎么过的。。。。。 > 注意,请用C++编译。 > > > #include <stdio.h> > //By 阿长 > > int a[100010]; > int min,max,dest,n,c,best; > > void qsort(int head,int tail){ > _asm{ > mov eax,head > mov edx,tail > cmp eax,edx > JGE over > > push ebx > mov ecx,eax > add eax,edx > shr eax,1 > shl eax,2 > shl ecx,2 > mov edx,a[eax] > mov ebx,a[ecx] > mov a[ecx],edx > mov a[eax],ebx > mov edx,tail > shl edx,2 > mov eax,ecx > > start: > cmp eax,edx > JGE end > mov ebx,a[eax] > > loop1: //while (i<j && a[i]<=a[j]) > cmp eax,edx > JGE end > cmp ebx,a[edx] > JG endloop1 > sub edx,4 > jmp loop1 > endloop1: > > mov ecx,a[edx] > mov a[eax],ecx > mov a[edx],ebx > add eax,4 > > loop2: //while (i<j && a[i]<=a[j]) > cmp eax,edx > JGE end > cmp a[eax],ebx > JG endloop2 > add eax,4 > jmp loop2 > endloop2: > > mov ecx,a[eax] > mov a[edx],ecx > mov a[eax],ebx > sub edx,4 > jmp start > > end: > pop ebx > shr eax,2 > push eax > > dec eax > push eax > push head > call qsort > add esp,8 > > pop eax > > inc eax > push tail > push eax > call qsort > add esp,8 > over: > > } > > } > > main(){ > > scanf("%d%d",&n,&c); > int i; > for (i=1;i<=n;i++) > scanf("%d",a+i); > qsort(1,n); > min=1; > max=(a[n]-a[1])/(c-1); > best=min; > dest=n*4; > c--; > _asm{ > push ebx > mov eax,min > mov edx,max > > begin: > cmp eax,edx > JG OK > add edx,eax > shr edx,1 > xor ecx,ecx > mov eax,8 > xor ebx,ebx > > loop3: > cmp eax,dest > JG cannot > > add ebx,a[eax] > sub ebx,a[eax-4] > add eax,4 > cmp ebx,edx > JL loop3 > xor ebx,ebx > inc ecx > cmp ecx,c > JGE can > jmp loop3 > > cannot: > dec edx > mov max,edx > mov eax,min > jmp begin > > can: > cmp best,edx > JGE notupdate > mov best,edx > > notupdate: > inc edx > mov min,edx > mov eax,edx > mov edx,max > jmp begin > > OK: > pop ebx > } > printf("%d\n",best); > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator