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 |
都用快排了,为什么还是超时??(数据方面的问题应该没有,就是超时...)(c/c++高人请进)代码如下: #include<stdio.h> #define MAX 100000 int num[MAX]; void QuickSort(long A[], long s, long t,long n) { long i=s,j=t+1; long x=A[s]; do{ do i++; while(A[i]<x); do j--; while(A[j]>x); if(i<j) { long temp=A[i]; long numt=num[i]; A[i]=A[j]; num[i]=num[j]; A[j]=temp; num[j]=numt; } } while(i<j); A[s]=A[j]; long numt=num[s]; num[s]=num[j]; A[j]=x; num[j]=numt; if(s<j-1) QuickSort(A,s,j-1,n); if(j+1<t) QuickSort(A,j+1,t,n); } int main() { long i,j,m,n,ns,s[MAX]; char c; bool b; scanf("%ld",&n); scanf("%c",&c); i=1; m=0; ns=0; while (i<=n) { scanf("%c",&c); if ((c>='0')&&(c<='9')) m=m*10+(int(c)-48); else if ((c>='A')&&(c<='Z')) { j=1; switch (c) { case 'A': case 'B': case 'C': { j=2; break; } case 'D': case 'E': case 'F': { j=3; break; } case 'G': case 'H': case 'I': { j=4; break; } case 'J': case 'K': case 'L': { j=5; break; } case 'M': case 'N': case 'O': { j=6; break; } case 'P': case 'R': case 'S': { j=7; break; } case 'T': case 'U': case 'V': { j=8; break; } case 'W': case 'X': case 'Y': { j=9; break; } default:j=0; } m=m*10+j; } else if (int(c)==10) { i++; b=true; for (j=1;j<=ns;j++) if (m==s[j]) { b=false; num[j]=num[j]+1; break; } if (b) { ns++; s[ns]=m; num[ns]=1; } m=0; } } QuickSort(s,1,ns,ns); b=true; for (i=1;i<=ns;i++) { if (num[i]>1) { b=false; m=10000000; for (j=1;j<=7;j++) { m=m/10; printf("%ld",s[i]/m); s[i]=s[i]%m; if (j==3) printf("-"); } printf(" %d\n",num[i]); } } if (b) printf("No duplicates.\n"); return 0; } 多谢多谢! Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator