PAT (Basic Level) Practice (中文) 1015 德才论

 

题目链接

 

要用快速排序,不然超时;

#include
#include
struct Data{
  long int id;
  int d;
  int c;
  int tote;
};
struct Data s[4][100000],r;
int cmp(const void *a,const void *b){
  struct Data e1=*(struct Data *)a;
  struct Data e2=*(struct Data *)b;
  if((e1.d+e1.c)!=(e2.d+e2.c)){
    return (e2.d+e2.c)>(e1.d+e1.c);
  }
  else if(e1.d!=e2.d){
    return e2.d>e1.d;
  }
  else{
    return e1.id>e2.id;
  }
}
int main()
{
  int a,b,N,L,H,g[4]={0};
  scanf("%d %d %d",&N,&L,&H);
  for(a=0;a=L&&r.c>=L){
      if(r.d>=H&&r.c>=H){
        b=0;
        s[b][g[0]++]=r;
      }
      else if(r.d>=H){
        b=1;
        s[b][g[1]++]=r;
      }
      else if(r.d>=r.c){
        b=2;
        s[b][g[2]++]=r;
      }
      else{
        b=3;
        s[b][g[3]++]=r;
      }
    }
  }
  qsort(s[0],g[0],sizeof(s[0][0]),cmp);
  qsort(s[1],g[1],sizeof(s[1][0]),cmp);
  qsort(s[2],g[2],sizeof(s[2][0]),cmp);
  qsort(s[3],g[3],sizeof(s[3][0]),cmp);
  printf("%d\n",g[0]+g[1]+g[2]+g[3]);
  for(a=0;a<4;a++)
    for(b=0;b

 

你可能感兴趣的:(乙级题)