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

复杂度只有o(n*lgn*m) 怎么会超时呢?求大牛指点迷津

Posted by snowbirds at 2009-04-23 21:16:09 on Problem 2153
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct banji
{
  int score;
  char name[31];
};  
int cmp1(const void *a,const void *b)
{
    banji *p=(banji *)a,*q=(banji *)b;
    return strcmp(p->name,q->name);
} 
int cmp2(const void *a,const void *b)
{
    banji *p=(banji *)a,*q=(banji *)b;
    return q->score-p->score;
} 
banji a[20001],b[20001];
int main()
{
    int i,j,n,m,k;
   scanf("%d",&n);
    
      for(i=0;i<n;i++)
      scanf("%s",a[i].name);      
      scanf("%d",&m);
      for(i=0;i<m;i++)
      {
      qsort(a,n,sizeof(banji),cmp1);
        for(j=0;j<n;j++)
        scanf("%d %s",&b[j].score,b[j].name);
        qsort(b,n,sizeof(banji),cmp1);
        for(j=0;j<n;j++)
       a[j].score=a[j].score+b[j].score;
         qsort(a,n,sizeof(banji),cmp2);        
         for(j=0;j<n;j++)
         {                       
           if(strcmp(a[j].name,"JLY")==0)
           {k=a[j].score;
             break;
           }
         }
         for(j=0;j<n;j++)
         {if(a[j].score>k)continue;else break;}
         printf("%d\n",j+1);
      
   }
   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