Commit 41f07718 authored by Chuanren Wu's avatar Chuanren Wu

simplify the code

parent 8b5d70d9
......@@ -24,13 +24,12 @@ static void redist(
std::vector<int> &res
)
{
const double denominator = std::accumulate(s.cbegin(), s.cend(), 0.0,
[&vl](double s, int i){ return s+vl[i]; } );
const double denominatorInv = 1 / denominator;
assert(!s.empty());
const double factor = 1/std::accumulate(s.cbegin(), s.cend(), 0.0,
[&vl](double s, int i){ return s+vl[i]; } );
int rest = n;
std::for_each(std::next(s.cbegin()), s.cend(), [&](int i){
res[i] = std::max(minRes[i], atLeast1(vl[i]*denominatorInv*n));
res[i] = std::max(minRes[i], atLeast1(vl[i]*factor*n));
rest -= res[i];
});
const int idFirst = *s.cbegin();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment