新boj3

guess

 #include <stdio.h> #include <stdlib.h> int cmp ( const void *a , const void *b){ return *(double *)a – *(double *)b; } int equ(double *trace,int *rank,int rowMax) { int i; for(i=1;i<rowMax;i++) { if(trace[i-1]<trace[i])return 0; else if(trace[i-1]==trace[i]&&rank[i-1]>rank[i])return 0; } return 1; } double Max=0; int check(double **score,double *trace,int *rank,int rowMax,int c,int step) { if(step!=rowMax) trace[step]=score[step][c]; if(step==0)//走到最后一行 { if(equ(trace,rank,rowMax)) { Max=trace[rowMax-1]; return 1; } else return 0; } else { int i; for(i=0;i<7;i++) if(check(score,trace,rank,rowMax,i,step-1))return 1; return 0; } } int main(int argc, char *argv[]) { double n,m,p; int i,j=0,player=0; scanf(“%d”,&player); while(player>0) { j++; double **row=(double **)malloc(sizeof(double)*player); for(i=0;i<player;i++) { scanf (“%lf%lf%lf”,&n,&m,&p); double score[3]; score[0]=n; score[1]=m; score[2]=p; qsort(score,3,sizeof(double),cmp); row[i]=(double *)malloc(sizeof(double)*7); row[i][0]=score[0]+score[1]+score[2]; row[i][1]=score[1]+score[2]; row[i][2]=score[0]+score[2]; row[i][3]=score[0]+score[1]; row[i][4]=score[2]; row[i][5]=score[1]; row[i][6]=score[0]; } double **row_rank=(double **)malloc(sizeof(double)*player); int *rank=(int *)malloc(sizeof(int)*player); for(i=0;i<player;i++) { scanf(“%d”,&rank[i]); row_rank[i]=row[rank[i]-1]; } double *trace=(double *)malloc(sizeof(double)*player); if(check(row_rank,trace,rank,player,0,player)) printf(“Case %d:%.2f/n”,j,Max); else printf(“No solution/n”); scanf(“%d”,&player); } system(“PAUSE”); return 0; }

点赞