失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 1080 Graduate Admission (30 point(s))

1080 Graduate Admission (30 point(s))

时间:2020-01-30 19:26:36

相关推荐

1080 Graduate Admission (30 point(s))

题解

STL应用。

#include<cstdio>#include<iostream>#include<vector>#include<algorithm>using namespace std;struct student {int rank, id;double Ge, Gi, grade;vector<int> sch;bool operator < (const student& rhs) const {return grade != rhs.grade ? grade > rhs.grade : Ge > rhs.Ge; }};struct school {int nownum, maxnum, lastrank;vector<int> child; };int n, m, k;int main() {scanf("%d%d%d", &n, &m, &k);vector<school> sc(m); //school vector<student> st(n); // studentfor(int i = 0; i < m; ++i) scanf("%d", &sc[i].maxnum);for(int i = 0; i < n; ++i) {st[i].sch.resize(k);st[i].id = i;scanf("%lf%lf", &st[i].Ge, &st[i].Gi);st[i].grade = (st[i].Ge + st[i].Gi) / 2;for(int j = 0; j < k; ++j) scanf("%d", &st[i].sch[j]);} sort(st.begin(), st.end());st[0].rank = 1;for(int i = 1; i < n; ++i) st[i].rank = st[i].grade == st[i - 1].grade && st[i].Ge == st[i - 1].Ge ? st[i - 1].rank : i + 1;for(int i = 0; i < n; ++i) {for(int j = 0; j < k; ++j) {int schoolid = st[i].sch[j];int rank = st[i].rank;int id = st[i].id;if(sc[schoolid].nownum < sc[schoolid].maxnum || sc[schoolid].lastrank == rank) {sc[schoolid].nownum++;sc[schoolid].lastrank = rank;sc[schoolid].child.push_back(id);break;}}}for(int i = 0; i < m; ++i) {sort(sc[i].child.begin(), sc[i].child.end());for(int j = 0; j < sc[i].child.size(); ++j) {if(j) printf(" ");printf("%d", sc[i].child[j]);}printf("\n");}return 0;}

如果觉得《1080 Graduate Admission (30 point(s))》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。