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

poj上TLE,南开oj上WA的自编快排……

Posted by JokerKS at 2010-10-09 20:53:12 on Problem 1442
In Reply To:这么短的代码怎么会WA??难道是理解错了题意??不就是排序么?各位帮我看看啊!! Posted by:JokerKS at 2010-10-09 18:36:11
#include<stdio.h>
int n,m,nm[31000],s[31000],p,u[31000];
void qs(int l,int r)
{
      int i,j;
      i=l;j=r;
      while(i<j)
         {
          while(i<j&&nm[i]<nm[j]) i++;
          if(i<j) {nm[0]=nm[i];nm[i]=nm[j];nm[j]=nm[0];j--;}
          while(i<j&&nm[i]<nm[j]) j--;
          if(i<j) {nm[0]=nm[i];nm[i]=nm[j];nm[j]=nm[0];i++;}
         }
      if(l<i-1) qs(l,i-1);
      if(r>i+1) qs(i+1,r);
}
int main()
{
     int i;
     while(scanf("%d%d",&n,&m)!=EOF)
     {
      for(i=1;i<=n;i++) scanf("%d",&s[i]);
      for(i=1;i<=m;i++) scanf("%d",&u[i]);
      for(i=1,p=1;i<=n;i++)
        {
         nm[i]=s[i];
         if(u[p]==i)
           {
            qs(1,i);
            while(u[p]==i)
               printf("%d\n",nm[p++]);
           }
        }
     }
     return 0;    
}

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