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

用二叉检索树、堆排

Posted by minimouse at 2003-12-20 20:06:34 on Problem 1002
In Reply To:怎么改才能不超时呢?望指点 Posted by:minidick at 2003-12-20 18:05:41
> #include <stdio.h>
> 
> void quick_sort(long *x, int low, int high)
> {
>  int i, j; long t;
>   i = low;
>   j = high;
>   t = *(x+low);
>   while (i<j)
>   {
>    while (i<j && *(x+j)>t)
>    {
>     j--;
>    }
> 
>    if (i<j)
>    {
>     *(x+i) = *(x+j);
>     i++;
>    }
> 
>    while (i<j && *(x+i)<=t)
>    {
>     i++;
>    }
> 
>    if (i<j)
>    {
>     *(x+j) = *(x+i);
>     j--;
>    }
>   *(x+i) = t;
>   quick_sort(x,low,i-1);
>   quick_sort(x,i+1,high);
>  }
> }
> 
> main()
> {
>    long a[100000];char c;
>    int i, j, n;
>    scanf("%d", &n);
>    for (i = 0; i < n; i++) {
>       a[i] = 0L;
>       for (j = 0; j < 7; j++) {
>             scanf("%c", &c);
>          switch (c) {
>             case 'A': case 'B': case 'C': case '2': a[i] = a[i] * 10L + 2L; break;
>             case 'D': case 'E': case 'F': case '3': a[i] = a[i] * 10L + 3L; break;
>             case 'G': case 'H': case 'I': case '4': a[i] = a[i] * 10L + 4L; break;
>             case 'J': case 'K': case 'L': case '5': a[i] = a[i] * 10L + 5L; break;
>             case 'M': case 'N': case 'O': case '6': a[i] = a[i] * 10L + 6L; break;
>             case 'P': case 'R': case 'S': case '7': a[i] = a[i] * 10L + 7L; break;
>             case 'T': case 'U': case 'V': case '8': a[i] = a[i] * 10L + 8L; break;
>             case 'W': case 'X': case 'Y': case '9': a[i] = a[i] * 10L + 9L; break;
>             case '1': a[i] = a[i] * 10L + 1L; break;
>             case '0': a[i] *= 10L; break;
>             default: j--;
>          }
>       }
>    }
>    quick_sort(a, 0, n - 1);
>    c = 1;
>    for (i = 0; i < n - 1; ) {
>       for (j = i + 1; j < n && a[j] == a[i];j++) ;
>       if (j > i + 1) {printf("%03ld-%04ld %d\n", a[i]/10000L,a[i]%10000L,j - i); c = 0;}
>       i = j;
>    }
>    if (c) printf("No duplicates.\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