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 |
求助我是按照contest report上的算法写的,测试数据也过了,可是提交就是wa,各位大虾帮忙看看,谢谢。 #include<stdio.h> int matrix[81][81]; int matrix1[81][81]; void shellsort(int *a,int *tag,int n) { int gap,i,j,t; gap=n/2; while(gap>0) { for(i=gap+1;i<=n;i++) { j=i-gap; while(j>0) { if(*(a+2*(*(tag+j)))>*(a+2*(*(tag+j+gap)))) { t=*(tag+j); *(tag+j)=*(tag+j+gap); *(tag+j+gap)=t; j=j-gap; } else j=0; } } gap=gap/2; } } void caculate(int M) { int i,j,s,h[81][81]; for(i=1;i<=M;i++) for(j=1;j<=M;j++) { h[i][j]=0; for(s=1;s<=M;s++) h[i][j]=h[i][j]+matrix1[i][s]*matrix[s][j]; } for(i=1;i<=M;i++) for(j=1;j<=M;j++) matrix1[i][j]=h[i][j]; } int main() { int M,i,j,a[81][2],tag[81],t,t1,max,sum; a[0][0]=-10003; a[0][1]=-10002; tag[0]=0; while(scanf("%d",&M)!=EOF) { for(i=1;i<=M;i++) { scanf("%d%d",&a[i][0],&a[i][1]); if(a[i][0]>a[i][1]) { t=a[i][0]; a[i][0]=a[i][1]; a[i][1]=t; } tag[i]=i; } i=1; max=0; shellsort(a,tag,M); while(1) { t=10002; t1=-1; for(j=i;j<=M;j++) if(a[tag[j]][0]>=a[tag[j-1]][1]&&a[tag[j]][1]<t) { t1=j; t=a[tag[j]][1]; } if(t1==-1) break; else { max++; i=t1+1; } if(i>M) break; } if(max==M) printf("0 1\n"); else { if(max==1) printf("%d %d\n",M-1,M); else { for(i=1;i<=M;i++) for(j=1;j<=M;j++) if(i<j&&a[tag[i]][1]<=a[tag[j]][0]) { matrix1[i][j]=1; matrix[i][j]=1; } else { matrix1[i][j]=0; matrix[i][j]=0; } for(i=1;i<max-1;i++) caculate(M); sum=0; for(i=1;i<=M;i++) for(j=1;j<=M;j++) if(matrix1[i][j]!=0) sum=sum+matrix1[i][j]; printf("%d %d\n",M-max,sum); } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator