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 |
不解地问:怎么会WA?这是程序,高手帮忙看一下有什么数据能让它出错? 顺便指出有啥更好的算法? 谢谢了 #include <stdio.h> int a[100][5]; int main() { int n,i,j,p,q,sum=0,b[5],max=65535,rez[5]; char s[5]; scanf("%d",&n); for (i=0;i<n;i++) { scanf("%s",s); a[i][s[0]-'A']=1; a[i][s[1]-'A']=2; a[i][s[2]-'A']=3; a[i][s[3]-'A']=4; a[i][s[4]-'A']=5; } /* for (i=0;i<n;i++) printf("%d %d %d %d %d\n",a[i][0],a[i][1],a[i][2],a[i][3],a[i][4]);*/ for (b[0]=1;b[0]<=5;b[0]++) /* A的位置 */ for (b[1]=1;b[1]<=5;b[1]++) /* B的位置 */ for (b[2]=1;b[2]<=5;b[2]++) /* C的位置 */ for (b[3]=1;b[3]<=5;b[3]++) /* D的位置 */ for (b[4]=1;b[4]<=5;b[4]++) { /* E的位置 */ if ((b[0]!=b[1])&&(b[0]!=b[2])&&(b[0]!=b[3])&&(b[0]!=b[4])&&(b[1]!=b[2])&&(b[1]!=b[3])&&(b[1]!=b[4])&&(b[2]!=b[3])&&(b[2]!=b[4])&&(b[3]!=b[4])) { sum=0; for (i=0;i<4;i++) for (j=i+1;j<5;j++) { for (p=0;p<n;p++) { if ((b[i]<b[j])&&(a[p][i]>a[p][j])) sum++; if ((b[i]>b[j])&&(a[p][i]<a[p][j])) sum++; } } if (max>sum) { max=sum; for (q=0;q<5;q++) rez[q]=b[q]; } } } for (j=1;j<6;j++) { for (i=0;i<5;i++) if (rez[i]==j) { printf("%c",i+'A'); break; } } printf(" is the median ranking with value %d.\n",max); /* for (i=0;i<5;i++) printf(" %d",rez[i]);*/ /* printf("%c%c%c%c%c is the median ranking with value %d.\n",rez[0]+'A'-1,rez[1]+'A'-1,rez[2]+'A'-1,rez[3]+'A'-1,rez[4]+'A'-1,max);*/ return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator