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 |
poj上TLE,南开oj上WA的自编快排……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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator