我这个测试答案对了,为什么通过率为0,是太慢了?
#include <stdio.h> #include <math.h> #include <string.h> int find(int a[],int n); double fen(int (*p)[],int max1,int max2,int max3,int max4,int max5); int main() { int n; scanf("%d",&n); int a[n+1][6]; int (*p)[6]=a+1; double w[n+1]; int z[n+1],x[n+1],c[n+1],v[n+1],e[n+1]; char b[n+1][10]; char q[10]; int max1,max2,max3,max4,max5; for(int i=1;i<=n;i++) { scanf("%s %d %d %d %d %d", b[i],&a[i][1],&a[i][2],&a[i][3],&a[i][4],&a[i][5]); z[i]=a[i][1]; x[i]=a[i][2]; c[i]=a[i][3]; v[i]=a[i][4]; e[i]=a[i][5]; } max1=find(z,n+1); max2=find(x,n+1); max3=find(c,n+1); max4=find(v,n+1); max5=find(e,n+1); for(int i=1;i<=n;i++){ w[i]=fen(p,max1,max2,max3,max4,max5); p++; } double o; for(int i=1;i<n-1;i++){ for(int j=1;j<=n-i;j++){ if(fabs(w[j]-w[j+1])>0.00001&&w[j]<w[j+1]){ o=w[j]; w[j]=w[j+1]; w[j+1]=o; strcpy(q,b[i]); strcpy(b[i],b[i+1]); strcpy(b[i+1],q); } else if(fabs(w[j]-w[j+1])<0.00001){ if(strcmp(b[i],b[i+1])>0){ strcpy(q,b[i]); strcpy(b[i],b[i+1]); strcpy(b[i+1],q); } } }} for(int i=1;i<=n;i++){ printf("%s %.5lf\n",b[i],w[i]); } return 0; } int find(int a[],int n){ int i,j; for(i=1;i<n-1;i++){ for(j=1;j<=n-i;j++){ if(a[j]<a[j+1]){ a[j]=a[j]^a[j+1]; a[j+1]=a[j]^a[j+1]; a[j]=a[j]^a[j+1]; } } } return a[1]; } double fen(int (*p)[],int max1,int max2,int max3,int max4,int max5){ double l; l=(double )*(*p+1)*600.0/(double )max1*0.25+(double )*(*p+2)*300.0/(double )max2*0.25+(double )*(*p+3)*300.0/(double )max3*0.25+(double )*(*p+4)*300.0/(double )max4*0.5+(double )*(*p+5)*300.0/(double )max5*0.5; return l; }
全部评论
(0) 回帖