标签:srm题解
#include <bits/stdc++.h>
using namespace std;
class MagicCandy {
public:
int whichOne(int n) {
int last = n;
while (n > 1) {
int d = sqrt(n);
if (d * d == n) --last;
n -= d;
}
return last;
}
};
#include <bits/stdc++.h>
using namespace std;
class MagicBlizzard {
public:
double expectation(vector <int> range, vector <int> amount) {
double ans = 0.0;
int n = range.size(), k = 0;
for (int i = 0; i < n; ++i) {
for (int j = n - 1; j > 0; --j)
if (range[j - 1] > range[j]) swap(range[j - 1], range[j]), swap(amount[j - 1], amount[j]);
for (int j = 0; j < amount[i]; ++j)
ans += 2.0 * (k++) / (2.0 * range[i] + 1) / (2.0 * range[i] + 1) + 1;
}
return ans;
}
};
标签:srm题解
原文地址:http://blog.csdn.net/mlzmlz95/article/details/46127289