1080 Graduate Admission (30 point(s))

题解

STL应用。

#include
#include
#include
#include
using namespace std;
struct student {int rank, id;double Ge, Gi, grade;vector sch;bool operator < (const student& rhs) const {return grade != rhs.grade ? grade > rhs.grade : Ge > rhs.Ge; }
};
struct school {int nownum, maxnum, lastrank;vector child; 
};
int n, m, k;
int main() {scanf("%d%d%d", &n, &m, &k);vector sc(m); //school vector 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;
}

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部