// 演算法與 C 版完全相同：時針角度 = hour*30 + minutes*0.5，分針角度 = minutes*6，
// Algorithm identical to the C version: hour angle = hour*30 + minutes*0.5,
// minute angle = minutes*6, take |difference|, then the smaller of it and 360-it.
// 取兩角差的絕對值，再回傳它與 360 減它之中較小的一個。O(1)。

#include <cmath>      // std::fabs / std::min 用到 / for fabs
#include <algorithm>  // std::min 提供較小值 / provides std::min

class Solution {
public:
    double angleClock(int hour, int minutes) {
        // hour % 12 讓 12 點對齊 0 度；每小時 30 度，每分鐘再加 0.5 度
        // hour % 12 aligns 12 o'clock to 0°; 30° per hour, plus 0.5° per minute
        double hourAngle = (hour % 12) * 30.0 + minutes * 0.5;

        // 分針：每分鐘 6 度 / minute hand: 6° per minute
        double minuteAngle = minutes * 6.0;

        // std::fabs 取浮點絕對值，得到兩針之間的角差
        // std::fabs gives the floating-point absolute value (the raw gap)
        double diff = std::fabs(hourAngle - minuteAngle);

        // std::min 回傳兩者中較小的；夾角與其補角(360-diff)取小
        // std::min returns the smaller of the gap and its complement (360 - gap)
        return std::min(diff, 360.0 - diff);
    }
};
