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 |
为什么WA 我用的是快速排序+统计 帮忙看看啊#include<stdio.h> int a[10001]; int count; void Quick_Sort(int left,int right) { int tmp; int i,j; int temp; i=left+1;j=right; tmp=a[left]; while(i<=j) { while(a[i]<=tmp&&i<=j) i++; while(a[j]>=tmp&&j>=i) j--; if(i<j){ temp=a[i]; a[i]=a[j]; a[j]=temp; count++; i++; j--; } } if(left!=j) { a[left]=a[j]; a[j]=tmp; count++; } if(left<j-1) Quick_Sort(left,j-1); if(j+1<right) Quick_Sort(j+1,right); } int main() { int t; int i; int n; int j; scanf("%d",&t); for(i=1;i<=t;i++) { count=0; scanf("%d",&n); for(j=1;j<=n;j++) { scanf("%d",&a[j]); } Quick_Sort(1,n); printf("%d\n",count); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator