B - Better Students Are Needed! 解説 by MatrixGroup
One can use function template to simplify hyman0’s solution.
To do this, one can write down the following code:
template<int a,int b>
bool cmp(const stu&c,const stu&d)
{
if(c.m*a+c.e*b!=d.m*a+d.e*b) return c.m*a+c.e*b>d.m*a+d.e*b;
return c.id<d.id;
}
where we use a struct
called stu
to store students’ scores and numers.
Then, we can use cmp<1,0>
, cmp<0,1>
, cmp<1,1>
and cmp<0,0>
to replace cmp1
to cmp4
.
Using function template, we can write only one comparing function instead of four, which can help us solve problems more quickly.(It is important in an AtCoder contest.)
Submission: 33298073
投稿日時:
最終更新: