| ||||||||||
| 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:SIMPLE 都过了,为啥WA啊,请大牛帮忙看一下In Reply To:SIMPLE 都过了,为啥WA啊,请大牛帮忙看一下 Posted by:666999 at 2009-05-10 23:37:58 > #include<iostream>
> using namespace std;
> long long a[500000],c[500000];
> long long MergeSort(long long a[],long long c[],int left,int right)
> {
> int i,j,mid,temp,count;
> long long total=0;
> if(left>right)
> return 0;
> mid=(left+right)/2;
> count=0;
> i=left;
> j=mid+1;
> while(i<=mid && j<=right)
> {
> if (a[i]>a[j])
> {
> total+=mid-i+1;//从右表移出一个元素,同时 total 累加左表此时的元素个数
> c[count++]=a[j++];
> }
> else
> {
> c[count++]=a[i++];
> }
> }
> return total;
> }
> int main()
> {
> int n,i,j;
> long long total;
> while (1)
> { scanf("%d",&n);
> if(n==0)
> break;
> for (i=0;i<n;i++)
> {
> scanf("%lld",&a[i]);
> }
> total=MergeSort(a,c,0,n-1);
> printf("%lld\n",total);
> }
> system("pause");
> return 0;
> }
>
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator