こういう類の問題は不得手だわー。厳しかった。
class LateProfessor {
public:
double getProbability(int waitTime, int walkTime, int lateTime, int bestArrival, int worstArrival) {
const int cy = waitTime + walkTime;
if (bestArrival == worstArrival) {
int t = bestArrival % cy;
if (waitTime < t) return t <= cy - lateTime;
return 0;
}
double ret = 0;
for (int t = bestArrival; t < worstArrival; ++t) {
int u = t % cy;
if (cy <= u + lateTime) continue;
if (u < waitTime) continue;
++ret;
}
return ret / (double)(worstArrival - bestArrival);
}
};
0 件のコメント :
コメントを投稿