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 |
Re:Runtime Error了好多次,不知道问题出在哪里?In Reply To:Runtime Error了好多次,不知道问题出在哪里? Posted by:2008550914 at 2010-03-02 10:19:36 > #include<iostream> > #define N 5000 > using namespace std; > > int a[N],b[N]; > > void MergeSort(int left,int right,__int64 &count) > { > if(left<right) > { > int mid=(left+right)/2; > MergeSort(left,mid,count); > MergeSort(mid+1,right,count); > int i=left,j=mid+1,k=left; > while(i<=mid&&j<=right) > if(a[i]<a[j]) b[k++]=a[i++]; > else > { > count=count+mid-i+1; > b[k++]=a[j++]; > } > while(i<=mid) > b[k++]=a[i++]; > while(j<=right) > b[k++]=a[j++]; > for(i=left;i<=right;i++) > a[i]=b[i]; > } > } > > int main() > { > int i,n; > __int64 count; > cin>>n; > while(n) > { > for(i=0;i<n;i++) > cin>>a[i]; > count=0; > MergeSort(0,n-1,count); > printf("%I64d\n",count); > cin>>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