Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这个我怎么写的那么恶心,而且慢,怎么优化一下呢?

Posted by sunmoonstar_love at 2005-08-05 22:16:42 on Problem 2535
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator