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 |
为什么这样的代码就是过不了。。。求指点#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator