题目1005:Graduate Admission
C语言源码:[cpp]
#include<stdio.h>
#include<stdlib.h>
#define maxsize 40010
typedef struct student
{
int ge,gi;
double grade;
int choice[10];
int num;
int rank;
}student;
student stu[maxsize];
int cmp(const void *a,const void *b)
{
student *aa=(student *)a;
student *bb=(student *)b;
if(aa->grade!=bb->grade)
return aa->grade>bb->grade?-1:1;
else
if(aa->ge!=bb->ge)
return bb->ge-aa->ge;
else
return aa->num-bb->num;
}
int cmp1(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int stack[101][maxsize];
int main()
{
int n,m,k,school[101],i,j,ge,top[101],s;
double grade;
while(scanf("%d %d %d",&n,&m,&k)!=EOF)
{
for(i=0;i<m;i++)
scanf("%d",&school[i]);
for(i=0;i<n;i++)
{
scanf("%d %d",&stu[i].ge,&stu[i].gi);
stu[i].grade=(double)(stu[i].ge+stu[i].gi)/2;
for(j=0;j<k;j++)
scanf("%d",&stu[i].choice[j]);
stu[i].num=i;
}
qsort(stu,n,sizeof(stu[0]),cmp);
grade=-1;
ge=-1;
j=0;
for(i=0;i<n;i++)
{
if(stu[i].grade!=grade||stu[i].ge!=ge)
{
stu[i].rank=i;
grade=stu[i].grade;
ge=stu[i].ge;
j=i;
}
else
stu[i].rank=j;
}
for(i=0;i<m;i++)
top[i]=0;
for(i=0;i<n;i++)
{
for(j=0;j<k;j++)
{
s=stu[i].choice[j];
if(school[s]>0)
{
stack[s][top[s]++]=i;
school[s]--;
break;
}
else
{
if(top[s]&&stu[stack[s][top[s]-1]].rank==stu[i].rank)
{
stack[s][top[s]++]=i;
break;
}
}
}
}
for(i=0;i<m;i++)
{ www.zzzyk.com
if(top[i]==0)
printf("\n");
else
{
for(j=0;j<top[i];j++)
stack[i][j]=stu[stack[i][j]].num;
qsort(stack[i],top[i],sizeof(stack[i][0]),cmp1);//注意输出时按序号递增输出
for(j=0;j<top[i]-1;j++)
printf("%d ",stack[i][j]);
printf("%d\n",stack[i][j]);
}
}
}
}
补充:软件开发 , C++ ,