問題
You are given a vector X containing the x-coordinates of several points. Each point starts at an infinitely high y-coordinate. Starting with the first point, each point falls down until it is either a distance of R away from a previously fallen point or it reaches y = 0. Each point (after the first point) will start falling only when the previous one stops. Return a vector , where the i-th element is the final y-coordinate of the i-th point.
class FallingPoints {
public:
vector<double> getHeights(vector<int> X, int R)
{
int i;
vector<double> ret;
for(i=0;i<X.size();i++)
{
if(i==0 || (X[i] - X[i-1]) > 10)
{
ret.push_back(0);
continue;
}
int c = R*R;
int a = (X[i]-X[i-1])*(X[i]-X[i-1]);
ret.push_back(sqrt(c-a)+ret[i-1]);
}
return ret;
}
};