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

为什么这样的代码就是过不了。。。求指点

Posted by 10226001 at 2011-08-22 21:42:57 on Problem 2893
#include<stdio.h>
#define N 1005
int num[N*N], res[N*N];
int sum;
void mergesort(int l, int r){
    int mid, i, j, tmp;
    if(r>l+1){
        mid=(r+l)/2;
        mergesort(l, mid);
        mergesort(mid, r);
        tmp=l;
        for(i=l, j=mid; i<mid&&j<r; ){
            if(num[i]>num[j]){
                res[tmp++]=num[j++];
                sum+=(mid-i);
            }
            else res[tmp++]=num[i++];
        }
        for(; j<r; j++){sum+=(mid-i);res[tmp++]=num[j];}
        for(; i<mid; i++)res[tmp++]=num[i];
        for(i=l; i<r; i++) num[i]=res[i];
    }
}
int main()
{
    int n, m, i, j;
    while(scanf("%d%d", &n,&m),n){
        for(i=0, j=0; i<n*m; i++, j++)
        {
            scanf("%d", &num[j]);
            if(num[j]==0)
            {
                if(m%2==0)
                    sum=n-1 - j/n;
                else
                    sum=0;
                j--;
            }
        }
        mergesort(0, n*m-1);
        if(sum%2)
            printf("NO\n");
       	else
            printf("YES\n");
    }
    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