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 |
这个我怎么写的那么恶心,而且慢,怎么优化一下呢?In Reply To:原来是more than a half...看了好久 Posted by:jackjack at 2005-08-05 21:13:54 #include <stdio.h> int n,p,i,j,simp[101],rating[101],min,max; bool sim[101],exist; int main() { scanf("%d%d",&n,&p); for(i=1; i<=p; i++) { sim[i] = true; simp[i] = 0; } for(i=0; i<n; i++) { for(j=1; j<=p; j++) scanf("%d",&rating[j]); min = 1001; max = -1; for(j=1; j<=p; j++) { if(rating[j]<min) min = rating[j]; if(rating[j]>max) max = rating[j]; } for(j=1; j<=p; j++) { if(rating[j]==max) sim[j] = false; if(rating[j]==min) simp[j]++; // printf("sim[%d] = %d max = %d, min = %d\n",j,sim[j],max,min); } } exist = false; for(i=1; i<=p; i++) { if(simp[i]<=n*0.5) sim[i] = false; if(sim[i]) exist = true; } if(exist) { for(i=1; !sim[i]; i++); printf("%d",i); for(i++; i<=p; i++) if(sim[i]) printf(" %d",i); printf("\n"); } else printf("0\n"); // scanf("\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