按照总分数和ge排序
按照分数顺序,再按照志愿顺序记录下每个志愿是否被录取,录取则break跳出循环
第一次写的答案有一个节点超时
#include
#include
#include
using namespace std;
typedef struct node
{
int id;
int ge;
int g1;
int g;
int choice[10];
bool flag;
}app;
typedef struct node1
{
int stunum;
app stuid[10];
int quo;
}school;
bool cmp1(app a,app b)
{
return a.id < b.id;
}
bool cmp(app a,app b)
{
if(a.g != b.g)
return a.g > b.g;
if(a.ge != b.ge)
return a.ge > b.ge;
}
int main()
{
int n , m, k;
int br = 0;
app a[40010];
school sch[110];
scanf("%d %d %d",&n,&m,&k);
for(int i =0;i0 && a[j].flag == false && a[j].choice[z] == i)
{
sch[i].quo--;
a[j].flag = true;
sch[i].stuid[sch[i].stunum]=a[j];
sch[i].stunum ++;
break;
}
}
}
}
for(int i = 0;i
问题应该是处理的时候中间有一个n3的循环,过于复杂
事实上最后一个循环没有意义,可以删除。可是还是超时
问题还有可能是学校的节点包含了学生志愿节点,其实只需要知道学生的id就够了
改进只记录学校上一个录取学生的id和记录录取学生id的数组。
还是超时。。。
超时问题找到了,在于cmp排序的时候 多了一个判断条件
不用比较ge是否相同
但是这样答案错误了。。。
#include
#include
#include
using namespace std;
typedef struct node
{
int id;
int ge;
int g1;
int g;
int choice[10];
}app;
typedef struct node1
{
int stunum;
int lastid;
int stuid[10];
int quo;
}school;
bool cmp1(int a,int b)
{
return a < b;
}
bool cmp(app a,app b)
{
if(a.g != b.g)
return a.g > b.g;
else
return a.ge > b.ge;
}
int main()
{
int n , m, k;
app a[40010];
school sch[110];
scanf("%d %d %d",&n,&m,&k);
for(int i =0;i0)
{
sch[i].quo--;
sch[i].lastid = j;
sch[i].stuid[sch[i].stunum] = a[j].id;
sch[i].stunum ++;
break;
}
}
}
for(int i = 0;i 0)
{
sort(sch[i].stuid,sch[i].stuid+sch[i].stunum,cmp1);
for(int j=0;j