SRM413 DIV2 Level.1

目的地までの距離、加速度、最高速度が与えられて、目的地にストップするまでにどれくらいの時間がかかるのか求めろという問題。
最高速度に達する場合とそうでない場合でわけないと駄目。

using System;
using System.Collections.Generic;
using System.Text;

class Subway2
{
    public double minTime(int length, int maxAcceleration, int maxVelocity)
    {
        double t = (double)maxVelocity / (double)maxAcceleration;
        double d = 0.5 * (double)maxAcceleration * t * t;

        if ((double)length <= 2 * d)
        {
            return 2.0 * Math.Sqrt((double)length / (double)maxAcceleration);
        }
        else
        {
            double d2 = (double)length - 2 * d;
            double t2 = d2 / (double)maxVelocity;

            return t2 + 2 * t;
        }
    }
}